Saturday, October 23, 2010

IQ puzzles - 2

Interview question puzzles

1.) There is a computer game, you have to play with the computer, the game is this
There are 17 sticks are shown in the screen, during each round you and computer has to take 1 to 6 sticks, i mean minimum 1 stick, maximum 6 stick. During the last round whoever takes the last stick is the looser,

Here the question is that you only have to win always against computer, first computer starts,
can you derive the formula that

Ans:
it is not 17 stick, it is actually 19 or 25 stick, lets take 25 stick. this is that expected answer.
trick is that in each round you should make sure that there are 6 sticks have gone,

solution:
Lets take there are 26 sticks, Suppose Computer is A, you are B, then during each round if you should take 6 minus what A takes, that is
A and B like (1, 5) , (2, 4), (3, 3), (4,2), (5, 1) => 6 stick have gone
so after 4 rounds only 1 stick will remain which the computer has to take




2.) There is magic beaker, which is empty, if you put one drop of water, for each seconds it doubles the drops, finally after 30 sec the beaker becomes full.
Now the question is if you put 2 drop in that empty beaker, how soon it will be filled ?

Ans:
29 seconds, but it will have 1 drop less.
Solution:
for one drop, for each second it doubles like this, 1 + 2 + 4 + 8 + 16 .... = 30 sec
for two drop, for each second it doubles like this, 2 + 4 + 8 + 16 ... = 29 sec, but 1 drop is less than the previous




3.) There is an array of size n, which has only 2 numbers, but duplicated, you have to write a step to sort the array in one iteration.
suppose if the array contains [2, 2, 1, 1, 2, 1, 2, 1, 1, 2] you have to bring the output as [1, 1, 1, 1, 1, 2, 2, 2, 2, 2]

Ans:
first you have to find what are those 2 number and count them in one iteration, then refill the array with the minimum number for its count, rest with the maximum of that number

4.)

IQ puzzles - 1

1.) There is an apple inside the bottle whose nozzle is very small than apple size, You cannot take the apple from the bottle. How that apple went inside or how the bottle is manufactured with the apple ?

Ans:
When that apple was small in the apple tree, it was sent inside the bottle and tied to the apple tree, so the apple was remain inside the bottle till it grows to bigger size




2.) There is a bridge, 4 people are standing at one end, they have one torch, they are trying to come to the other end, the question here is how soon they can come by the following criterias
a) At a time only 2 can travel with that torch,
b) without the torch they cannot travel.
c) After reaching the other end, one of them should come back with the torch so that it will be used again

those four travels in different speed, time taken by each of them is as follows,
1 min, 2 min, 10 min, 5 min,
When 2 of them comes to the other end the time taken by them is the maximum
that is for example if 10 and 1 are going together, then time taken is 10 min

Final question is that they all should come to the other end within 17 min, how can they come ?

Answer:

step-1: 1, 2 went to the other end and 1 returns back, so time is = 3
step-2: 10, 5 went to the other end and 2 returns back, so time is = 12
step-3: 1, 2 went to the other end, so time is = 2

Finally 3 + 12 + 2 = 17 mins




3.) there are 3 bags A, B, C. Bag A contains 50 oranges, but labeled as apples, Bag B contains 50 apples but labeled as oranges, but the third bag C contains 100 apples and oranges mix but labeled as (oranges and apples), these 3 bags are in front of you, you should take minimum number of fruits from any of the bags randomly and you should identify those 3 bags.

Ans: 2

steps:
lets take x and y are first and second fruits, taken from A or B or C,
considering the following options the answer is 2.

option-1
x = apple from A, A contains orange
y = orange from B, B contains apple
then C contains the mix

option-2
x = apple from B, B contains orange
y = mix from C, C contains mix
A contains the apple

The other way around, the minimum try needed is only 2





4.) Write steps to calculate tax for a salary, like this
a) upto 99 no tax
b) 100 to 199 10%
c) 200 to 299 20%
d) above 300 30%

Ans:
lets take salary as s, now apply the follow steps

if s < 100
tax = 0;
else if s < 200
tax = (s - 100) * 0.1
else if s < 300
tax = (s - 100) * 0.2 + 10
else above 300
tax = (s - 200) * 0.3 + 20 + 10

5.) Write a Binary search algorithm