Sunday, 29 May 2016

Two door, which path leads to heaven?

You are standing before two doors. One of the path leads to heaven and the other one leads to hell.

There are two guardians, one by each door.
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?
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Answer:
"If I ask the other guard about which side leads to heaven, what would he answer?"

Let say path of heaven is 'Left' then...
Answer from the guard who always speaks truth... 'Right'.
Answer from the guard who always lie... 'Right'.

So you can get that hell is on Right side and heaven is in Left.  :D

Note:
If you ask "which side leads to heaven" then
Answer from the guard who always speaks truth... 'Left'.
Answer from the guard who always lie... 'Right'.
:) 

)

Find black/white pair of socks

There are 10 black socks and 10 white socks in a drawer.
Now you have to go out wearing your shoes.
So how many maximum number of times you need to remove the sock from drawer so that you can go out?

You can remove only 1 sock at a time. Obviously, you can’t go outside wearing different socks!
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Answer:
3

Find the celebrity in the party

There are n people in a party, they might or might not know each others names.

There is one celebrity in the group, celebrity does not know any of n-1 peoples by name and all n people know celebrity by name.

You are given the list of people’s names, You can ask only one question from the people. Do you know this name ?

How many maximum number of questions you need to ask to know the celebrity name?

Note: assume all names are unique. and you know the persons by name(but don’t know if he is celebrity)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Answer:
n-1 questions

If we ask a question to a person A about person B that... "Do you know him?"
If person A say yes... then A is not celebrity but B is definitely.
If person A say  no... then A might be a celebrity but B is definitely not a celebrity.

If we are asking this question to everyone in the party, then in worst case when last two persons are remaining then we get our answer.
So (n-1) questions are require to ask.

Two egg puzzle

We are given two eggs, and access to a 100-story building. Both eggs are identical.
The aim is to find out the highest floor from which an egg will not break when dropped out of a window from that floor. If an egg is dropped and does not break, it is undamaged and can be dropped again. However, once an egg is broken, that’s it for that egg.

If an egg breaks when dropped from floor n, then it would also have broken from any floor above that. If an egg survives a fall, then it will survive any fall shorter than that.

The question is:
What strategy should you adopt to minimize the number egg drops it takes to find the solution?.
And what is the worst case for the number of drops it will take?
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Answer:
14

x + (x-1) + (x-2) +...+ 1 = 100
Sigma(x) = 100
x*(x+1) / 2 = 100
x(x+1) = 200
x = 13.65
x = 14

Detailed answer:
http://datagenetics.com/blog/july22012/index.html
http://www.programmerinterview.com/index.php/puzzles/2-eggs-100-floors-puzzle/

25 horse, 5 tracks, find 3 fastest horses

We have 25 horses, and we want to pick the fastest 3 horses out of those 25.
We have only 5 tracks. Means, in each race, only 5 horses can run at the same time.

What is the minimum number of races required to find the 3 fastest horses without using a stopwatch?
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Answer:
7

First 5 race should be held among 25 horses.
6th race should be held among... winner of every race.
7th race should be among...
( Second and Third horses from the group of first winner of 6th race,
  top two horses from the group of  second winner of the 6th race,
  top horse from the  group of third winner of 6th race. )