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.)
No comments:
Post a Comment