## Recent Interview Questions

- 0of 0 votes
consider a battlefield to be made up of square cells of unit dimensions. a soldier on the battlefield can move from a cell to all(8) of it's neighboring cells. soldier has a gun with with him which he can shoot the targets up to any distance along any of the 8 possible directions (north,east,west,south,north-east,north- west,south- east,south- west). also some sell are bulletproof which prevents bullets to pass but soldier can walk over them as if it were a normal cell.he can destroy the target from a bulletproof cell but not from a cell behind it.

position of a target/ soldier can be given by the cell, they are on.given the position of the target, starting position of a target and position of all the bullet proof cells. you have to tell the position of closest shooting point i.e the cell from which, the soldier can shoot the target and is closest to the starting position of the soldier. if there are more than such cells, output all of them.

Input/output specifications :

Input specifications :

I) size of the battlefield { integer pair (N,M) : battlefield will be of N*M size )

II) staring position of the soldier {integer pair (i,j)}

III) position of the target {integer pair (x,y) : position of the cell on which target is mounted}

IV) position of the all bullet proof cells { list of integer pair a#b : each element in the list is a position of bullet proof cells }

output specifications :

sequential list of integer pair i#j (cell) that are closest shoot points and must fallow row wise traversal.

Note: if the output list contains four shoot points : (2,1), (1,2), (3,2), (2,4) on a 4x4 battle field.

then the correct output will be {1#2,2#1,2#4,3#2} not {1#2,2#1,3#2,2#4}

Examples:

Input : {2,2} {2,1} {2,2} {1#1,1#2}

output : 2#1

below is the method signature in java:

public static String[] nearest_shoot_point(int[] input1,int[] input2,int[] input3String[] input4){

}

- 0of 0 votes
write a prog/method to convert number to character (as in old mobile phone).

e.g. 2 entered 1 = A

2 entered 2 = B

2 entered 3 = C

# = space

22#22 = B B etc.

- 0of 0 votes
Add a third dimension of time to a hashmap , so ur hashmap will look something like this - HashMap<K, t, V> where t is a float value. Implement the get and put methods to this map. The get method should be something like - map.get(K,t) which should give us the value. If t does not exists then map should return the closest t' such that t' is smaller than t. For example, if map contains (K,1,V1) and (K,2,V2) and the user does a get(k,1.5) then the output should be v1 as 1 is the next smallest number to 1.5

- 0of 0 votes
Find first duplicate in an array where:

Array has N integers ranging from 0 to n-1.

(Multiple elements can be duplicated multiple times)

in time complexity O(n) and space complexity O(1)

- 0of 0 votes
Insert a value into a sorted linked list.

Using C/C++ write a small function (around 5 lines in the body) to insert a value in a sorted linked list. Take into consideration that the list might be empty at first, and the function should cover the cases of insertion at the head and tail...

PS what the interviewer is looking for is the ability to write a small C/C++ code that solves the question and not the algorithm per se which is trivial

- 0of 0 votes
You are given two objects, Student and Course, and there exist a many to many relation between them. One student can be enrolled for more than one course and there can be many students enrolled for a single course. Design an effective data structure to store such data keeping in mind that the time complexity for search should be optimum. A search can be for the list of students enrolled for a single course, or for the list of courses a single student is enrolled.

- -1of 1 vote
You are standing before two doors.One door leads to the heaven and the other leads to Hell but you don't know what hides behind the doors. There are two gatekeepers. You know one of them always tells the truth and the other always lies, but you don't know who is the honest one and who is the liar.

You can only ask one question to one of them in order to find the way to heaven. What is the question?

- 0of 0 votes
I am trying to write a method that will return true if a binary tree is full and complete (each node has 2 children or none and all the leaves of the tree are at the same depth).

My idea is to use recursion. I will check for any node if its left son has number of children that is equal to its right son's number of children. If so, I will return true, otherwise false.

The algorithm will look like this:`public class Utils { public boolean isFullCompleteTree(Tree<Integer> t) { TreeInfo rootInfo = isFullCompleteTree(t.getRoot()); return rootInfo.valid; } public TreeInfo isFullCompleteTree(Node<Integer> node) { boolean valid = true; if (node == null) { return new TreeInfo(true, 0); } TreeInfo rightInfo = isFullCompleteTree(node.goRight()); TreeInfo leftInfo = isFullCompleteTree(node.goLeft()); if ((!rightInfo.valid) || (!leftInfo.valid)) { valid = false; } if (rightInfo.numChildern != leftInfo.numChildern) { valid = false; } return new TreeInfo(valid, rightInfo.numChildern + leftInfo.numChildern + 1); } } class TreeInfo { public boolean valid; public int numChildern; public TreeInfo(boolean valid, int numChildern) { this.valid = valid; this.numChildern = numChildern; } }`

I didn't include the tree implementation but it is pretty straightforward.

The idea of the algorithm is to check if in every node the number of right son's children is equal to the left son's children. If a tree is not full and complete, then in some node this rule will not apply.

Do you think that my algorithm is correct or am I missing something?

- 0of 0 votes
Given a 2 dimensional point of a rectangle and its area, find permutations of all the other 3 points of the rectangle in 2-D space.

Ex:- Given X=(0,0) and A=1

(0,1),(1,0),(1,1)

(0,-1),(-1,0),(-1,-1)

- 0of 0 votes
glitch is a walking robort moves in a peculiar problem: it takes x steps forward , then x+1 steps backward, then 2x steps forward, x+2 steps backward,3x steps forward x+3 steps backward , and so on... until it has taken y steps,glitch turns 180 degrees before continuning with its pattern . write a program that prompts x and y and total number of steps taken and outputs how many steps away from its starting point

- 0of 0 votes
Given a password in number : Write an algorithm to print all possible combinations of that password.

Hint: - Try to go from all possible combinations of lower bound to the valid upper bounds

- 0of 0 votes
Basket ball hit rates The hit rate of the basketball game is given by the number of hits divided by the number of chances. For example, you have 73 chances but hit 15 times,

then your hit rate is 15/73=0.205 (keep the last 3 digits). On average, you have 4.5 chances in each basketball game. Assume the total number of games is 162. Write a function for a basketball player. He will input the number of hits he has made, the number of chances he had, and the number of remaining games. The function should return the number of future hits,

so that he can refresh his hit rate to 0.45

- 0of 0 votes
Find the depth of Binary search tree without using recursion?

- 0of 0 votes
Add a button to save the picture in AIR or AS3

I have a file attachment [here][1]:

https://drive.google.com/file/d/0B9BcYjTM8tPoaHFxckpENjFidWc/view?usp=sharing

I tried I try to add a button for interface to download the image in the phone folder in AIR or AS3

Or make a photo wallPaper for phon.

Can anyone help me??

And experience it in the attached file .

![enter image description here][2]

[1]: https://drive.google.com/file/d/0B9BcYjTM8tPoaHFxckpENjFidWc/view?usp=sharing

[2]: http://i.stack.imgur.com/OYThn.jpg

http://stackoverflow.com/questions/29915396/add-a-button-to-save-the-picture-in-air-or-as3

- 1of 1 vote
There are N pots. Every pots have some water in it. They may be partially filled. So there is a Overflow Number 0 associated with every pot which tell how many minimum stone pieces are require for that pot to overflow. So if for a pot 0-value is 5 it means minimum 5 stone pieces should be put in that pot to make it overflow. Initially a crow watched those pots and by seeing the water level he anticipated 0-value correctly for every pot ( that is he knew 01 to On). But when he came back in evening he found that every pot is painted from outside and he is not able to know which pot has what 0-value. Crow wants some K pots to overflow so that he can serve his child appropriately. For overflow of pots he need to search for stone in forest( assume that every stone has same size). He wants to use minimum number of stones required to overflow K pots. But only he know the 0-value of pots he doesn't know now which pot has what 0-value. So the task is that in what minimum number of stones he can make K pots overflow in worst case.

Input/Output Specifications Input Specification: 1) A array 0 corresponding to 0-value of N pots {01, 02, On} 2) Number of pots 3) K -value ( number of pots which the crow wants to overflow}

Output Specification: Minimum number of stones required to make K pots overflow in worst case. Or -1 if input is invalid

Example: Let say there are two pots pot 1 has 0 value of 5 , 01= 5 pot 2 has 0 value of 58, 02= 58 Let say crow wants to make one of the pot to overflow. If he know which pot has what 0-value he would simple search for 5 stones and put then in pot 1 to make it overflow. But in real case he doesn't know which pot has what 0-value so just 5 stones may not always work. However he does know that one pot has 0-value S and other has 58. So even in worst case he can make one of the pot overflow just by using 10 stones. He would put 5 stones in one pot if it doesn't overflow he would try the remaining 5 in the other pot which would definitely overflow because one of the pot has 0-value of 5. So the answer for above question is minimum 10 stones even in worst case. Input : Input 1= {5,58} Input 2= 2 Input 3= 1 Output : 10

- 0of 0 votes
Rahul is playing a very interesting game. He has some N different type of match boxes. All match boxes may have different number of matchsticks (S1, S2, S3... Sn).

Rahul chooses two random numbers F and K. K should be less than N. The game is that Rahul wants to select any K match boxes out of N match boxes such that total number of matchsticks in these K selected match boxes should be multiple of F.

At the sametime Rahul wants that sum matchsticks of all the selected match boxes should be minimum possible.

Input Specifications:

1) Array S = {S1,S2,S3,...Sn} of size N corresponding to the number of match sticks in N matchboxes(0<=N<=1000}

2) F-Value (as explained above)

3) K-Value ( as explained above)

Output:

1 2 3 4 5 Here 3 is the number of matchsticks in matchbox I II III IV V minimum possible total number of matchsticks such that the conditioned explained in the problem statement is satisfied. Output -1 if it is not possible or invalid input.

For example, there are 5 match boxes i.e., N = 5

Let's say K is 3 (Rahul has to choose any 3 matchboxes)

Let's say F is 5(sum of matchsticks in 3 selected matchboxes should be multiple of 5).

Rahul can choose II, III and V matchboxes which would give the total sum of 10 which is multiple of F i.e., 5. And 10 is the minimum possible matchsticks possible in the above case.

So you have to answer the minimum possible matchstick(sum of the matchsticks in the selcted matchboxes) but the conditions given above should be satisfied.

- 1of 1 vote
The prime numbers between 1,000,000 and 1,000,100 are:

1000003, 1000033, 1000037,1000039, 1000081, 1000099

and its sum is = 6000292.

What is the sum of all prime numbers between 1,000,000,000,000 and 1,000,000,100,000?

- 0of 0 votes
You are given the Ancestor matrix of a Binary tree, write an C program/function to construct the corresponding tree.

For example, the below tree:

10

/ \

5 30

/ \ \

4 8 40

/

1

Will have the following ancestor Matrix

1 4 5 8 10 30 40

1 0 1 1 0 1 0 0

4 0 0 1 0 1 0 0

5 0 0 0 0 1 0 0

8 0 0 1 0 1 0 0

10 0 0 0 0 0 0 0

30 0 0 0 0 1 0 0

40 0 0 0 0 1 1 0

Essentially, in the ancestor matrix, each node has a row and a column (may not be the same). The value at a[i][j] will be 1 iff node of Node representing j‘th column is the ancestor of node representing the i‘th row.

Write an C program/function that can construct the binary tree from a given Ancestor matrix(2 dimensional array as input to the function).

- 1of 1 vote
Given an unsorted array, find Kth smallest element in it.

A = 12, 3, 17, 0, 9, 6, 100

K = 3 -> 6

- 0of 0 votes
write a function that takes two integers, k and n, with 0 ≤ k ≤ n, and prints out all subsets of size k of the integers 1, ..., n, one subset per line. The order of the subsets and the order of elements within the line doesn't matter.

example 1: print_subsets(k=1, n=2);

1

2

example: print_subsets(k=2, n=3);

3 1

2 3

1 2

- 0of 0 votes
Design a Binary search tree using Epic as Input

- 0of 0 votes
Design a class to implement chess and checkers game individually.

- 0of 0 votes
design a class to provide information about the disease of a patient with details like who reported the disease(patient/doctor/relative), different symptoms of the disease, severity, method that returns when was that disease detected in that patient. Along with info if it is allergy and not a disease so that it can be updated easily along with record the time of the allergy report.

- 0of 0 votes
create a class to tell a nurse the frequency of medicine that a patient must take, i.e. a system to tell patients when to take medication and create a class with an object that holds temperatures of a person and can say whether or not they have a fever.

- 0of 0 votes
design a class to store the information of the patients visiting to the hospital., i.e. a class which stores name, address, phone number, male/female, prefix to the name. Also, how will you handle job in case of multiple phone numbers/addresses, multiple locations

(If a person is both at 12 PM in USA on a date, then that date is different from date in India), how will you handle the validations of these fields when the user enters the values.

- 1of 3 votes
there are 1 billion stars and you are standing at the earth. From the earth , you know the distance of all 1billion stars. Find the nearest 1 million stars from the earth.

- 0of 0 votes
Given a stairs of very large size. You are standing at the 0th step. You have to perform n actions. 1st action means you can move forward to 1 step or not. 2nd action is you can move 2steps or keep standing. 3rd action is you can move 3 steps or not and so on. Given is a step no. k which is broken. You can't stand on this step. Find out after performing n actions what can be the maximum no. of steps you can go.

- 0of 0 votes
Implement a program to reverse the linear linked list in pairs. it should handle both even number of nodes and odd number of nodes. if odd number of nodes, the last node will be the last node after reversion.

Do not move the data in the nodes. Do manipulate node pointers/references. the nodes themselves need to be manipulated, not just the data in the nodes.

For example, if the initial linear linked is,

1->2->3->4->5

after reverse it should be,

2->1->4->3->5

- 0of 0 votes
Implement a function that checks if the given binary tree is binary search tree(BST). Use tree operations to solve this. do not try solving by pre-order traversal of the tree and then checking if the array is sorted.

instead, traverse the tree for checking if it is BST.

- 0of 0 votes
Write a function that takes two arguments one array of integers that ranges between 0 and 9 and second the target sum(again integer). It produces all permutations strings of the input digits that equals the target sum.

For example, if input is array 2, 3, 5 and target sum is 10, then the output should be:

22222 because 2+2+2+2+2 = ,10

2323 as 2+3+2+3 = 10

3232

55

2233

3322

532

235

352

etc.,