MyAnatomy Coding Questions and Answers

My Anatomy Coding Question and Answers

MyAnatomy Coding Questions and Answers for 2023 is discussed on this page, along with detailed analysis, difficulty, importance, most asked languages in MyAnatomy etc.

Stay tuned to get updated with latest MyAnatomy Coding question with Answers.

Myanatomy Coding Question and Answers

MyAnatomy Coding Questions and Answers

Time Depends on Company
Questions 2-3(Depend on Company)
Negative Marking No
Languages C, C++, Java, Python
On this page, you will find all the MyAnatomy Coding Questions and Answers with solutions that were asked in previous papers.

The level of question is depends on the company. It may vary from easy to hard. So we suggest that you should practice a good number of questions so that you can easily solve the problems.

  • No of Questions : 2-3(Depends on Company)
  • Time : Depends on Company

IMPORTANT NOTE :

  1. There will be no negative marking in coding section.
  2. The number of questions may vary from company to company as the companies have their own standard of taking exams.
  3. Time duration depends on the number of questions and the company for which the test is being conducted.

Program 1:
HOSTEL WARDEN

There is a hostel warden in some XYZ hostel. He is very strict with students. He has some set of rules to allow students to let them out. Students are in random order but warden don’t allow them in that way.
Rule 1- whose initial is a prime value should go out before whose initial is a composite value.
Rule 2- if two students have prime value , a student with less value goes out first
Rule 3- if two students have composite value , a student with greater value goes out first
NOTE:- consider the ASCII value of the initial to find it is prime or composite.

Input Format

The first line of input contains the number of students N

  • The second line of input contains random order of the students S.
    (students at index zero goes out first and students at index N-1 goes last)

Constraints

  • 1<=number of students <=105
  • 33<=ASCII Of Characters<=126

Output Format

  • The single line of output should contain the required modified order of students to go out.

Test Cases

Case 1

  • Input
    13
    Kkunjkhahorin
  • Output
    akkuronnjihhK

 

  • Explanation
    For primes: a<k
    For Composite: K<h<i<j<n<o<r<u
    Adding up logic, the required answer is akkuronnjihhK
  •  

Program 2: Jagannath and his Brothers

Jagannath was with two of his young brothers in work. He wants to work less, and wants his brothers to work more, as he is a lazy person. Now, in the work field, there is an array of buildings, from where they can earn money. So that there arises no conflict between his brothers that who earns more, he arrives in one building, tells his brother that the very building will bring the most money (Which may not be true), and tells one of his brothers to go to the left and another one to go to the right.

You have to write a program so that you can predict which building will be getting Jagannath, and how much money each of his friends are gonna earn.

Input Format

  • First line saying the number of test cases, n.
  • Then next n pairs of lines, first one depicting the number of buildings k and second one containing k space separated integers denoting the number of earnings possible.

Constraints

  • 1 <= n <= 10 ^ 6
  • 1 <= k  < n
  • -10 ^ 9 <= a[i] <= 10 ^ 9 (Earnings)
  • 1 <= t <= 25

Output Format

  • n lines, with the index of building jagannath working, space separately the money His brothers each making. If the combination is not possible, answers are 0.

Test Cases

Case 1

  • Input
    1
    5
    1 2 2 4 5
  • Output
    4 5

 

  • Explanation

    Jagannath will work in the 4th building, and his brothers are making 5 rupees each.
  •  

Program 3: SUSHIL's MADNESS

Shushil has gone crazy after he lost a big amount of his money in the share market. Now he keeps all the money he has distributed in his room and calculates them in a very problematic way. Every time he calculates hisnetworth, he writes it down adding  with the last 3 rooms he has one.

Then after that when he reaches the next room he adds the last 3 rooms’s money with the money found in that room and adds again. Suppose he is in ith room, he will add i-1,i-2 and i-3th rooms money with ith one and add it into his net worth (if the rooms exist).

Given an array of money in the rooms, find what will he calculate as his net worth?

Input Format

  • First line saying the number of rooms, r
  • Next line r space separated money amounts in each room
  • Next line contains an m, denoting a number that we will use to take module of the final value

Constraints

  • 1<= r <= 1018
  • 1<= a[i] <= min(600,r)
  • 1<= M <= 1018

Output Format

  • Print the answer on the first line

Test Cases

Case 1

  • Input
    5
    1 2 3 4 5
    100
  • Output
    34
  •  

Program 4: Simple problem

Mr X is a teacher of maths. He came across a very simple problem. In the problem you have to arrange the numbers in an ascending order and calculate the total number of swaps required. The number of swaps must be minimum. But Mr X is busy with some other tasks and you being his favourite student , so he asks you to solve this problem.

Input Format

  • First line contains the number n.
  • n space separated integers

Constraints

  • 1<=T<=100
  • 1<=N<=100
  • 1<=A[ ] <=1000

Output Format

  • Print the answer on the first line

Test Cases

Case 1

  • Input
    4
    4 3 1 2
  • Output
    2

 

  • Explanation
    Swap index 0 with 3 and 1 with 2 to form the sorted array {1, 2, 3, 4}.
  •  

Program 5: Encryption is everything!

Vaibhav is head of regiment 22 and he used to send some information to the Ashish who is head of 33rd regiment. The problem here is there are enemies nearby regiments. So Vaibhav has security issues now. He decides to encrypt the information and then transfer to Ashish.

But Vaibhav has no knowledge on encryption. Help Vaibhav to encrypt the data.

He is instructing you to encrypt as follows

if the ascii value of “z” is 3(assumption) so it will be replaced by “c”.

if ascii value of “a” is 3(assumption) so it will be replaced by “d”

Input Format

  • A string of alphabets in lowercase

Constraints

  • 1<=lenght_of_string<=10^5

All lowercase alphabets

Output Format

  • A string following the above mentioned encryption rule

Test Cases

Case 1

  • Input
    helpme
  • Output
    hbpxrb

 

  • Explanation
    ‘h’ + ascii(h) positions = h
    ‘e’ + ascii(e) positions = b
    ‘l’ + ascii(l) positions = p
    ‘p’ + ascii(p) positions = x
    ‘m’ + ascii(m) positions = r
  •  

Question 6 : Possible ways of discount

Problem Statement – Festival season running on so every shop is giving discounts.You went for a shop to buy some products from them. They have some unique conditions , only if you met that condition you will get discounts conditions are-

  • You need to buy at least two products.
  • The total cost of all products from the set should be at least Rupees L and at most Rupees R.
  • The difference in the cost of the costliest and the cheapest of the chosen products must be at least x.

Find the number of ways that you get a discount from the shopkeeper.

Input Format:

  • The first line contains four integers n, l, r, x – the number of products in the shop, the minimum and maximum value of total cost of the chosen products and the minimum difference in cost between the costliest product and the cheapest product among the chosen products, respectively.
  • The second line contains n integers C1, C2, …Cn,-the cost of each product.

Constraints

  • 1<=n<=15
  • I<=l<=r<=10^9
  • 1<=x<= 10^6
  • 1 <=c[i]<=10^6

Output format:

  • Print the number of ways that you can get a discount from the shopkeeper.

Sample Input 1

3 5 6 1

1 2 3

Sample Output 1

2

Explanation 1

set1 – 2 and 3 

set2- 1,2 and 3

only these set met all the conditions

Sample input  2

4 40 50 10

10 20 30 25

Sample Output 2

2

Sample input 3

4 5 234 2

10 9 12 11

Sample Output 3

8

Question 7: Strange rule

Problem Statement – There are two friends Ram and Shyam. They saw each other after a very long time. Then they remember the rule they make when they are of very small age. They have decided that whenever they see each other they will move towards each other in a very dramatic way.

  • Let’s say Ram and Shyam are ‘D’ meters apart.
  • Ram moves 1 meter in each step he takes but Shyam moves are increases linearly starting from 1, i.e., he moves 1 meter in his first step then 2 meters on the second, 3 meters on the third step and so on till he cannot take a step.
  • Assume they both take steps simultaneously till shyam is able to make a step. Whenever shyam can’t make a step, he waits patiently at that place and the rest of the distance is covered by Ram. 
  • Calculate the minimum number of steps they take in total before meeting each other.
  • Your task is to output the minimum number of total steps required before Ram and Shyam can meet each other.

Input Format:

  • The first line contains the number of test cases ‘T’.
  • The next ‘T’ line contains the distance ‘D’.

Constraints:

  • 1 T 105
  • 1 D 105

Output Format:

  • Output ‘T’ lines with each line containing a single integer denoting the minimum number of jumps they take before hugging each other for each test case.

Sample Input

1

3

Sample Output

3

Explanation

  • Let Ram be at position 0 of x-axis and Shyam be at position 3 of the x-axis.
  • Ram jumps to position 1 and simultaneously Shyam jumps to position 2.
  • Now Shyam can’t make a jump because if he does so, then he will be jumping over Ram which is undesirable. So she patiently waits at position 2.
  • Finally, Ram jumps to position 2 and they hug each other
  • You can clearly see 3 jumps are required. Two by Ram and One by Shyam.
  • So the output is 3.

Sample Input

1

5

Sample Output

4

Question 8: Help Charlie to win

Problem Statement – In Charlie and the Chocolate factory , the factory owner decided to select the winner by a competition. In the competition there are N chocolates and they have to calculate in how many days they can eat N chocolates provided some condition. On the first day, it is allowed to eat max 1 chocolate. If he eats i chocolates on a given day, he can eat i,i+1 or i-1 chocolates on the next day. On the last day, he can’t eat more than 1 chocolate. Now Charlie wants to win the game. He is good at programming so he thinks to find the answer by programming . Now help Charlie to win the competition.

Input Format

  • The first line contains an integer T (1 <_T <_1000) denoting the number of test cases.
  • Each of the next Tlines contains an integer N (1<_ N<_ 10^9).

Output Format

  • Output T lines. On each line output the minimum number of days for each test case,

Sample Input

3

9

1

4

Sample output

5

1

3

Explanation

Case 1:1 + 2 + 3 + 2 + 1

Case 2:1

Case 3:1 + 2 + 1

Question 9: Encryption is EVERYTHING!

Problem Statement – Vaibhav is head of regiment 22 and he used to send some information to the Ashish who is head of 33rd regiment. The problem here is there are enemies nearby regiments. So Vaibhav has security issues now. He decides to encrypt the information and then transfer to Ashish.

But Vaibhav has no knowledge on encryption. Help Vaibhav to encrypt the data.He is instructing you to encrypt as follows

  • if the ascii value of “z” is 3(assumption) so it will be replaced by “c”.
  • if ascii value of “a” is 3(assumption) so it will be replaced by “d”

Input Format

  • A string of alphabets(all alphabets are in lowercase ie. a to z).

Constraints:

  • 1<=lenght_of_string<=10^5
  • All lowercase alphabets

Output Format :

  • A string following the above mentioned encryption rule ( All alphabets must be in lowercase a to z).

Sample Input 0

helpme

Sample Output 0

hbpxrb

Explanation 0

‘h’ + ascii(h) positions = h

‘e’ + ascii(e) positions = b

‘l’ + ascii(l) positions = p

‘p’  + ascii(p)  positions = x

‘m’  + ascii(m)  positions = r

Question 10: Lexicographical arrangement

Problem Statement – You are given  a single line of strings separated by space . You need to arrange them lexicographically. A lexicographical order is the dictionary order.

Input

  • Input contains a single line of strings in a space separated manner.
  • String contains only uppercase English letters.

Output

  • Print the sorted array.

Example

INPUT :

ASH AAB JKR FTE

OUTPUT :

AAB ASH FTE JKR

Question 11: Special MATHS

Problem Statement – X Æ A-12 believes special MATHS , where there is no rule of operator precedence. All operators have equal precedence. If + comes before * then + should perform before *.

Consider an example

  • 1-2*3 in general maths gives -5 as answer , but in special MATHS it is -3
  • Evaluate the given string 

Input format:

  • A string

Output format:

  • Evaluated answer

Constraints

  • string has only numbers (1 to 9) , operators(+,-,*,/)
  • Between every number there will be a operator

Sample input:

1-2*3

Sample output:

-3

Explanation:

1-2=-1

-1*3=-3

 

Sample input 1:

1+2-3*4

Sample output 1:

0

Explanation

1+2=3

3-3=0

0*4=0

Question 12: Love test

Problem Statement – A couple(both are professors in Mathematics)  got a doubt about who loves their partner more. So they decided to play a maths game to decide who loves more. They will take some numbers and the one who makes that number to 1 will win. They can only reduce numbers by following some rules. Check if the number is a power of 2. If it is a power of 2, the person divides the number by 2 Else, the person subtracts the number by the highest power of 2 lower than the number. Then the person gives the newly obtained number to their partner.

Sorry I didn’t tell you the names of the couple, they are  Steve and Carter.

Always Steve starts the game.

Input format

  • First line contains an integer T denoting the number of games.
  • Each of the next T lines contain an integer N, the starting number for the game.
    • 0<T<11
    • 0<N<2^64

Note: Since N can be a very large number, use appropriate data types for the variables.

Output format

  • For each of the T games, print the person name who loves more on a new line.

Note: The output format should be followed strictly. 

Sample Input

2

6

3

Sample Output

Carter

Steve

Explanation

Game 1:

Steve starts, 6 is not a power of 2. Hence, Steve subtracts 6 by the highest power of 2 smaller than 6, which is 4:  6-4 = 2

Carter receives 2. 2 is a power of 2. Hence, Player B divides 2 by 2 to get 1.

Since Carter reduced the number to 1, Carter is the winner.

Game 2:

Steve starts. 3 is not a power of 2. Hence, Player A subtracts 3 by highest power of 2 smaller than 3, which is 2:  3-2 = 1

Hence, Steve wins.

Sample Input

3

10

12

13

Sample Output

Steve

Carter

Steve

Question 13: Manipulative Proyash

Problem Statement – Proyash manipulates every number in his math book. So oneday his math sir became frustrated with him and gave him as punishment two numbers, that he had to change one to another. But then he has given some numbers, and Proyash is not allowed to reach any other number out of them. Now Proyash can only change one digit in the number each time.

You have to predict how many turns he will take to reach the number. If it is impossible to reach there, print -1.

Input Format:

  • Two strings in first two lines
  • One Integer n denoting how many numbers they can reach
  • N number of lines in next with integers


Output Format:

  • Single line denoting the minimum number of steps

Sample input

101 123 5

111

132

122

131

145

Sample Output:

4

Explanation:

101 -> 131 -> 132 -> 122 -> 123

4 changes needed.

FAQ's

What will be the difficulty level of MyAnatomy Coding Section ?

  The Coding Question asked in MyAnatomy are of three difficulty type – 

  • 1 Question of Easy Level
  • 1 Question of Medium Level
  • 1 Question of Hard Level

 Do I study the My Anatomy coding free content or the MyAnatomy paid material ?

Obviously, the paid material will have more content and more questions will be available to practice in paid material. The free content is only to help you understand the type of questions asked. Free material won’t be enough to help you to crack the exams.