Please login

#### Prepinsta Prime

Video courses for company/skill based Preparation

#### Prepinsta Prime

Purchase mock tests for company/skill building

# MyAnatomy Coding Questions and Answers

## MyAntomy Coding Question and Answers

MyAnatomy Coding Questions and Answers for 2021 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 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 :

- There will be no negative marking in coding section.
- The number of questions may vary from company to company as the companies have their own standard of taking exams.
- 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

#include<bits/stdc++.h>

using namespace std;

int main()

{

int n;cin>>n;

string s;cin>>s;

int prime[128];

prime[0]=prime[1]=0;

int p=2;

for(int i=2;i<128;i++) prime[i]=1;

while(p*p<=127)

{

if(prime[p])

{

for(int i=p*p;i<=127;i+=p)

prime[i]=0;

}

p++;

}

string s1,s2;

for(auto i:s)

{

if(prime[i]) s1+=i;

else s2+=i;

}

sort(s1.begin(),s1.end());

sort(s2.begin(),s2.end());

reverse(s2.begin(),s2.end());

cout<<s1<<s2;

}

import java.util.Collections;

import java.util.Scanner;

import java.util.Vector;

public class Applicartion22 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int n = sc.nextInt();

String s = sc.next();

boolean primes[] = new boolean[127];

for(int i=0;i<127;i++) {

primes[i] = true;

}

primes[0]=false;

primes[1]=false;

int p = 2;

while(p*p<=126) {

if(primes[p]) {

for(int i=p*p;i<127;i+=p) {

primes[i]=false;

}

}

p+=1;

}

Vector<Character> s1 = new Vector<>();

Vector<Character> s2 = new Vector<>();

for(int i=0;i<s.length();i++) {

char ch = s.charAt(i);

if(primes[(int)ch]) {

s1.add(ch);

}else {

s2.add(ch);

}

}

Collections.sort(s1);

Collections.sort(s2);

for(int i=0;i<s1.size();i++) {

System.out.print(s1.get(i));

}

for(int i=s2.size()-1;i>=0;i--) {

System.out.print(s2.get(i));

}

}

}

n=int(input())

s=input()

prime=[True]*127

prime[0]=prime[1]=False

p=2

while(p*p<=126):

if(prime[p]):

for i in range(p*p,127,p):

prime[i]=False

p+=1

s1=[]

s2=[]

for i in s:

if(prime[ord(i)]):

s1.append(i)

else:

s2.append(i)

s1.sort()

s2.sort(reverse=True)

print(s1,s2)

s1.extend(s2)

print("".join(s1))

## 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.

#include<bits/stdc++.h>

using namespace std;

void func()

{

int k;cin>>k;int ans1=0, ans2=0;

vector<int> a(k),l(k),r(k);

for(int i=0;i<k;i++) cin>>a[i];

l[0]=a[0];r[k-1]=a[k-1];

for(int i=1;i<k;i++) l[i]=l[i-1] + a[i];

for(int i=k-2;i>=0;i--) r[i]=r[i+1] + a[i];

for(int i=1;i<k-1;i++)

if(l[i-1]==r[i+1]){ans1=i+1;ans2=l[i-1];break;}

cout<<ans1<<" "<<ans2<<endl;

}

int main()

{

int n;cin>>n;

while(n--)

func();

}

import java.util.Scanner;

import java.util.Vector;

public class Application23 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int t = sc.nextInt();

for(int z=0;z<t;z++) {

int k = sc.nextInt();

int ans1=0,ans2=0;

int[] a=new int[k];

int[] l=new int[k];

int[] r=new int[k];

for(int i=0;i<k;i++) {

a[i] = sc.nextInt();

}

l[0]=a[0];

r[k-1]=a[k-1];

for(int i=1;i<k;i++)

l[i]=l[i-1] + a[i];

for(int i=k-2;i>=0;i--)

r[i]=r[i+1] + a[i];

for(int i=1;i<k-1;i++) {

if(l[i-1]==r[i+1]){

ans1=i+1;ans2=l[i-1];

break;

}

}

System.out.println(ans1 + " " + ans2);

}

}

}

for t in range(int(input())):

n=int(input())

ar=list(map(int,input().split()))

left,right=[0]*n,[0]*n

left[0]=ar[0]

right[-1]=ar[-1]

for i in range(1,n):

left[i]=left[i-1]+ar[i]

for i in range(n-2,-1,-1):

right[i]=right[i+1]+ar[i]

i,j,m,y=0,2,0,0

while(i<n and j<n):

if(left[i]==right[j]):

m=left[i]

y=i+2

break

i+=1

j+=1

print(y,m)

## 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

#include<bits/stdc++.h>

using namespace std;

int main()

{

int m,r,ans=0;cin>>r;

vector<int> a(r);

for(int i=0;i<r;i++) cin>>a[i];

cin>>m;

for(int i=0;i<4;i++)

for(int j=0;j<=i;j++)

ans+=a[j];

for(int i=4;i<r;i++)

ans+=(a[i]+a[i-1]+a[i-2]+a[i-3]);

cout<<ans%m;

}

import java.util.Scanner;

public class Application24 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int m,r,ans=0;

r = sc.nextInt();

int[] a = new int[r];

for(int i=0;i<r;i++)

a[i]=sc.nextInt();

m = sc.nextInt();

for(int i=0;i<4;i++)

for(int j=0;j<=i;j++)

ans+=a[j];

for(int i=4;i<r;i++)

ans+=(a[i]+a[i-1]+a[i-2]+a[i-3]);

System.out.println(ans%m);

}

}

ans=0

r=int(input())

a=list(map(int,input().split()))

m=int(input())

for i in range(4):

for j in range(i+1):

ans+=a[j]

for i in range(4,r):

ans+=(a[i]+a[i-1]+a[i-2]+a[i-3])

print(ans%m)

## 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}.

#include<bits/stdc++.h>

using namespace std;

int main()

{

int n;cin>>n;

vector<int> arr(n);

for(int i=0;i<n;i++) cin>>arr[i];

vector<pair<int,int>> ap(n);

for(int i=0;i<n;i++)

{ap[i].first=arr[i];ap[i].second=i;}

sort(ap.begin(),ap.end());

vector<bool> v(n,false);

int ans=0;

for(int i=0;i<n;i++)

{

if(v[i]||ap[i].second==1) continue;

int cs=0,j=i;

while(!v[j])

{

v[j]=1;

j=ap[j].second;

cs++;

}

if(cs>0)ans+=cs-1;

}

cout<<ans;

}

import java.util.*;

import java.io.*;

class Prep

{

public int minSwaps(int[] arr, int N)

{

int ans = 0;

int[] temp = Arrays.copyOfRange(arr, 0, N);

HashMap<Integer, Integer> h= new HashMap<Integer, Integer>();

Arrays.sort(temp);

for (int i = 0; i < N; i++)

{

h.put(arr[i], i);

}

for (int i = 0; i < N; i++)

{

if (arr[i] != temp[i])

{

ans++;

int init = arr[i];

swap(arr, i, h.get(temp[i]));

h.put(init, h.get(temp[i]));

h.put(temp[i], i);

}

}

return ans;

}

public void swap(int[] arr, int i, int j)

{

int temp = arr[i];

arr[i] = arr[j];

arr[j] = temp;

}

}

class Main

{

public static void main(String[] args) throws Exception

{

Scanner ss = new Scanner(System.in);

int n = ss.nextInt();

int[] a;

a = new int[n];

for (int i=0;i<n;i++)

{

Scanner in = new Scanner(System.in);

a[i]= in.nextInt();

}

n = a.length;

System.out.println(new Prep().minSwaps(a, n));

}

}

n=int(input())

ar=list(map(int,input().split()))

arrpos = list(enumerate(ar))

arrpos.sort(key = lambda it : it[1])

vis = {k : False for k in range(n)}

ans = 0

for i in range(n):

if(vis[i] or arrpos[i][0]==i):

continue

j=i

cycles=0

while(vis[j]==False):

vis[j]=True

cycles+=1

j=arrpos[j][0]

if(cycles>0):

ans+=cycles-1

print(ans)

## 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

#include<bits/stdc++.h>

using namespace std;

int main()

{

string s;

cin>>s;

for(auto i:s)

{

i='a'+(i-'a'+(i%26))%26;

cout<<i;

}

}

import java.util.Scanner;

public class Application25 {

public static void main(String[] args) {

Scanner ss = new Scanner(System.in);

String s = ss.nextLine().trim();

for(int i=0;i<s.length();i++) {

char c = s.charAt(i);

char ch=(char)('a'+(c-'a'+(c%26))%26);

System.out.print(ch);

}

}

}

s=input()

low="abcdefghijklmnopqrstuvwxyz"*10

ans=""

for i in range(len(s)):

ans+=low[(low.index(s[i])+(ord(s[i])%26))]

print(ans)

## 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

import sys

sys.setrecursionlimit(10**5)

n,l,r,x=map(int,input().split())

ar=list(map(int,input().split()))

st=[]

ans=0

def solve(arr, index, subarr):

global ans

if index == len(arr):

if (len(subarr) != 0):

if(len(subarr)>=2 and max(subarr)-min(subarr)>=x and l<=sum(subarr)<=r):

ans+=1

else:

solve(arr, index + 1, subarr)

solve(arr, index + 1, subarr+[arr[index]])

return

solve(ar, 0, [])

print(ans)

## 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

#include<bits/stdc++.h>

using namespace std;

int main()

{

int a,d,t;

cin>>t;

while(t--)

{

cin>>d;

int cnt=0,t=1,j=1,tp=0,jp=d;

while(d>0)

{

if(t+j>d)

{d-=t;tp+=t;cnt+=1;}

else if(t+j==d)

{

if(tp+t==jp-j)

{cnt+=2;d-=(t+j);jp-=j;tp+=t;}

else

{

d-=t;tp+=t;cnt++;

}

}

else{

d-=(t+j);

tp+=t;jp-=t;j++;cnt+=2;

}

}

cout<<cnt<<endl;

}

}

import java.util.*;

import java.io.*;

class Main {

public static void main(String[] args) {

Scanner sc= new Scanner(System.in);

int n=sc.nextInt();

for (int i = 0; i < n; i++)

{

int d=sc.nextInt();

int cnt=0;

int t=1;

int j=1;

int tp=0;

int jp=d;

while(d>0)

{

if(t+j>d)

{

d=d-t;

tp+=t;

cnt+=1;

}

else{

if(t+j==d)

{

if(tp+t==jp-j)

{

cnt+=2;

d=d-t-j;

jp-=j;

tp+=t;

}

else

{

d=d-t;

tp+=t;

cnt+=1;

}

}

else

{

d=d-t-j;

tp+=t;

jp-=j;

j+=1;

cnt+=2;

}

}

}

System.out.println(cnt);

}

}

}

for t in range(int(input())):

d=int(input())

cnt,t,j,tp,jp=0,1,1,0,d

while(d>0):

if(t+j>d):

d=d-t

tp+=t

cnt+=1

elif(t+j==d):

if(tp+t==jp-j):

cnt+=2

d=d-t-j

jp-=j

tp+=t

else:

d=d-t

tp+=t

cnt+=1

else:

d=d-t-j

tp+=t

jp-=j

j+=1

cnt+=2

print(cnt)

## 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

import java.util.Scanner;

public class Application20

{

public static void main (String[]args)

{

Scanner sc = new Scanner (System.in);

int t = sc.nextInt ();

while (t > 0)

{

int n = sc.nextInt ();

if (n == 1)

{

System.out.println ("1");

continue;

}

else

{

int[] dp = new int[n];

for (int i = 0; i < n; i++)

{

dp[i] = 999999999;

}

dp[1] = 1;

for (int i = 1; i < n; i++)

{

if (2 * i < n)

{

dp[2 * i] = Math.min (dp[2 * i], dp[i] + 1);

}

if (2 * i + 1 < n)

{

dp[2 * i + 1] = Math.min (dp[2 * i + 1], dp[i] + 1);

}

if (2 * i - 1 < n)

{

dp[2 * i - 1] = Math.min (dp[2 * i - 1], dp[i] + 1);

}

}

System.out.println (dp[n - 1] + 1);

t--;

}

}

}

}

for t in range(int(input())):

n=int(input())

dp=[999999999999999]*(n+5)

if(n==1):

print(1)

continue

dp[1]=1

for i in range(1,n):

if(2*i<n):

dp[2*i]=min(dp[2*i],dp[i]+1)

if(2*i+1<n):

dp[2*i+1]=min(dp[2*i+1],dp[i]+1)

if(2*i-1<n):

dp[2*i-1]=min(dp[2*i-1],dp[i]+1)

print(dp[n-1]+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

#include<bits/stdc++.h>

using namespace std;

int main()

{

string s;

cin>>s;

for(auto i:s)

{

i='a'+(i-'a'+(i%26))%26;

cout<<i;

}

}

import java.util.Scanner;

public class Application25 {

public static void main(String[] args) {

Scanner ss = new Scanner(System.in);

String s = ss.nextLine().trim();

for(int i=0;i<s.length();i++) {

char c = s.charAt(i);

char ch=(char)('a'+(c-'a'+(c%26))%26);

System.out.print(ch);

}

}

}

s=input()

low="abcdefghijklmnopqrstuvwxyz"*10

ans=""

for i in range(len(s)):

ans+=low[(low.index(s[i])+(ord(s[i])%26))]

print(ans)

## 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

#include<bits/stdc++.h>

using namespace std;

int main()

{

string s1;getline(cin,s1);

vector<string> v;

istringstream ss(s1);

while(ss)

{

string w;ss>>w;

if(w=="") break;

v.push_back(w);

}

sort(v.begin(),v.end());

for(auto i:v) cout<<i<<" ";

}

import java.util.Arrays;

import java.util.Scanner;

public class Application21

{

public static void main (String[]args)

{

Scanner sc = new Scanner (System.in);

String s = sc.nextLine ();

String[] str = s.split (" ");

Arrays.sort (str);

for (int i = 0; i < str.length; i++)

{

System.out.print (str[i] + " ");

}

}

}

print(*sorted(input().split()))

## 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

s=list(input())

op="+-*/"

ans=""

flag=0

for i in s:

if i in op:

flag=1

a=i

elif i not in op and flag==1:

ans=str(eval(ans+a+i))

elif(i not in op):

ans+=i

flag=0

print(ans)

import java.util.Scanner;

public class Application27

{

public static void main (String[]args)

{

Scanner sc = new Scanner (System.in);

String s = sc.nextLine ().trim ();

String ans = "";

int flag = 0;

char a = '1';

for (int i = 0; i < s.length (); i++)

{

char ch = s.charAt (i);

if (ch == '+' || ch == '-' || ch == '*' || ch == '/')

{

flag = 1;

a = ch;

}

else if (ch != '+' && ch != '-' && ch != '*' && ch != '/'

&& flag == 1)

{

if (a == '+')

{

int temp = Integer.parseInt (ans) + (ch - '0');

ans = String.valueOf (temp);

}

if (a == '-')

{

int temp = Integer.parseInt (ans) - (ch - '0');

ans = String.valueOf (temp);

}

if (a == '*')

{

int temp = Integer.parseInt (ans) * (ch - '0');

ans = String.valueOf (temp);

}

if (a == '/')

{

int temp = Integer.parseInt (ans) / (ch - '0');

ans = String.valueOf (temp);

}

}

else if (ch != '+' && ch != '-' && ch != '*' && ch != '/')

{

ans += ch;

flag = 0;

}

}

System.out.println (ans);

}

}

## 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

for t in range(int(input())):

n=int(input())

if(n==1):

print('Carter')

continue

if(n==2):

print('Steve')

continue

cnt=0

n=n-1

for i in range(65):

if(n&(1<<i)):

cnt+=1

if(cnt%2==1):

print('Carter')

else:

print('Steve')

import java.util.Scanner;

public class Application28

{

public static int highestPowerof2 (long n)

{

int p = (int) (Math.log (n) / Math.log (2));

return (int) Math.pow (2, p);

}

public static void main (String[]args)

{

Scanner sc = new Scanner (System.in);

int t = sc.nextInt ();

for (int z = 0; z < t; z++)

{

long n = sc.nextLong ();

if (n <= 3)

{

System.out.println ("Steve");

continue;

}

boolean ans = true;

while (n > 1)

{

int power = highestPowerof2 (n);

if (power == n)

{

n /= 2;

if (n == 1)

{

break;

}

}

else

{

n -= power;

if (n == 1)

{

break;

}

}

ans = !ans;

}

if (ans)

{

System.out.println ("Steve");

}

else

{

System.out.println ("Carter");

}

}

}

}

## 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.

#include<bits/stdc++.h>

using namespace std;

int main ()

{

int a, b, t;

cin >> t;

while (t--)

{

cin >> b >> a;

if (b - a == 1)

cout << (a & b);

else

cout << max ((b & (b - 1)), ((b - 1) & (b - 2)));

cout << endl;

}

}

import java.util.Scanner;

public class Application25

{

public static void main (String[]args)

{

Scanner ss = new Scanner (System.in);

int t = ss.nextInt ();

for (int i = 0; i < t; i++)

{

int b = ss.nextInt ();

int a = ss.nextInt ();

if (b - a == 1)

System.out.println (a & b);

else

System.out.println (Math.

max ((b & (b - 1)), ((b - 1) & (b - 2))));

}

}

}

## 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.

Login/Signup to comment