Saturday, 18 June 2016

Interview Questions with Solution

1. There are two sorted arrays . Find the median of array obtained by Merging these two arrays.

2. Transpose of a matrix

3. Garbage Collection in Java. Mark & Sweep Algorithm

4. Fill 4 Lt using 5 Lt and 3 Lt Jars.

5. Given an array that contains both positive and negative integers, find the product of the maximum product subarray

6. Rotate a Matrix clockwise by 90 degree.

7. Puzzle : There are n Prisoners standing in a line with increasing height such that each prisoner can see the hat color of prisoners standing ahead of him but he cannot see his own hat color. Hats are of only two color , Red or Blue. Now each prisoner has to say his hat color. If he is right, he lives otherwise the Jailer will shoot him. Find the strategy to save maximum number of prisoners.

8. There is a binary stream coming . You need to print true or false based on the fact whether the number formed is divisible by 5 or not.

9. Print all subset of a Set .

10 Given a string of any length. print all possible combinations of string length k

11 Given a matrix, print in spiral order.

12 Verify whether given tree is BST or not.

13 Various approached to implement dictionary

14 Various approaches and complexities for array rotation problem.

15 Infinite streams of number, find top k numbers.

16 You have 9 balls, equally big, equally heavy - except for one, which is a little heavier.
How would you identify the heavier ball if you could use a pair of balance scales only twice?

17 Detect & return the intersection point of 2 linked list.

18 Multiple 2 numbers using bitwise operator.

19 Given a number, find the next highest number formed using the same digits.

20 Clone a linked list given 2 pointers, next & arbit.

21 Given inorder and postorder traversal make the actual tree.

22 Find the longest distance between two nodes in a tree.

23 Print right view of a binary tree

24 Design a DS which does push, pop and min in O(1)

25 Find the maximum sum subarray from a given array.Array can have negative elements too.We have to print initial and final position of the subarray. Hint: Kadane’s Algorithm

26 You’ve got someone working for you for seven days and a gold bar to pay him. The gold bar is segmented into seven connected pieces. You must give them a piece of gold at the end of every day. What and where are the fewest number of cuts to the bar of gold that will allow you to pay him 1/7th each day?

27 Write the code to find a given word in the given string

28 You are about to leave for holiday, but you forgot socks! You race back to your room, but all the lights are off, so you can't see the color of the socks.
Never mind, because you remember that in your drawer there are ten pairs of white socks, ten pairs of black socks, and eleven pairs of blue socks, but they are all mixed up.
How many of your socks do you need to take before you can be sure to have at least one matching pair?

29 Consider a regular telephone dial up. It has generally three alphabets for each digit. For example, ABC for 2 and so on.
Given a number. Print all the possible strings by taking one alphabet corresponding to each digit in number.
Input: 254
Output: AKH, AJG etc.

30 Write programme to find first repeating element in an array

31 Find a number in a 2-D matrix sorted horizontally and vertically.

32 How to find the minimum element in a rotated array? e.g. 4 5 6 1 2 3

33 How to know if a number is a power of 2 in O(1)?

34 Given n points in a plane which form a polygon. Find if a random point exists inside that polygon or not

35 There is a paragraph having million characters. You have to find out the first non –repeating character in the complete paragraph

36 There are N nuts and N bolts, u have to find all the pairs of nuts and bolts in minimum no. of iteration (comparision). All the nuts/bolts might have different diameter.

37 There are chocolates each worth x. You have total amount y with you. And you can exchange z wrappers for 1 chocolate. So in this way how many chocolates he can eat.

38 There is a pond in which there is x kg ice on 1st November, it becomes 2x on 2nd November then 4x,8x,16x,32x and so on.Like this whole pond is filled with ice on last day i.e. 30th November. On which day pond was filled with half the ice ?

39 you have 100 coins on table, 60 heads and 40 tails. With your eyes closed, how can you separate the coins into 2 groups such that each group has same number of tails.

40 You have 3 jars that are all mislabeled. One jar contains Apple, another contains Oranges and the third jar contains a mixture of both Apple and Oranges.
You are allowed to pick as many fruits as you want from each jar to fix the labels on the jars. What is the minimum number of fruits that you have to pick and from which jars to correctly label them?

41Find the row with maximum ones in a 2D array where in each row all 1s occur before all 0s

42 Check if a given sum is availabe in an array.

43 Design a ladder and Snake Problem with TWO Player and Code it.

44 A person can have 1 step, 2 step, or 3 steps. How much combination he can have to climb on a ladder of n and code.

45 In array only 1 element is unique rest are 2 times. How to find that?

46 Random Pointer in Linked list. Clone it.

47 There are 2 people A and B. Both A and B have equal speed of walking. Both A and B have equal speed of running. Now assume that A runs for half the time and walks for half the time. While, B runs for half the distance and walks for half the distance. Can we tell conclusively who will win in a race?

48 Find square root of ‘N’ without using square root function.

No comments :

Post a Comment