Interview Puzzles

Stack of 'must-know' interview puzzles !

Four glasses puzzle

Four glasses or tumblers are placed on the corners of a square Lazy Susan. Some of the glasses are upright (up) and some upside-down (down). A blindfolded person is seated next to the Lazy Susan and is required to re-arrange the glasses so that they are all up or all down, either arrangement being acceptable, which will be signalled by the ringing of a bell. The glasses may be re-arranged in turns subject to the following rules:

 Any two glasses may be inspected in one turn and after feeling their orientation the person may reverse the orientation of either, neither or both glasses.

After each turn the Lazy Susan is rotated through a random angle. The puzzle is to devise an algorithm which allows the blindfolded person to ensure that all glasses have the same orientation (either up or down) in a finite number of turns. The algorithm must be non-stochastic i.e. it must not depend on luck.

Days of month

How can you represent days of month using two 6 faced dice ?

You can write one number on each face of the dice from 0 to 9 and you have to represent days from 1 to 31.

 For example for 1, one dice should show 0 and another should show 1, similarly for 31 one dice should show 3 and another should show 1.

The wine lover King and prisoners

Long time back, there was a wine lover King with a cellar of 1000 bottles of delightful and very expensive wine. A neighboring queen once planned to kill the wine lover King and sent a servant to poison the wine. Fortunately (or say unfortunately) the king’s guards caught the servant after he had only poisoned one bottle. Though the guards did’t know which bottle but knew that the poison was so strong that even if diluted 100,000 times it would still kill the king. Furthermore, it would take one month to have an effect. The king decided he would get some of the prisoners in his vast dungeons to drink the wine. Being a clever king he knews he only required to murder not more than 10 prisoners – which was not a high death rate by any means – and would still be able to drink the rest of the wine (999 bottles) at his anniversary party in 5 weeks time. Explain what was in mind of the king, how would he be able to do so ?

Grand Father, Father and Grand Son

One Grand Father, one Father and one Grand Son.
Sum of their ages is 140 Years.
Grand Son’s age in month is equal to Grand Father’s age in years.
Grand Son’s age in days is equal to Father’s age in weeks.
How old are the three in years?

Lucky Prince

A king wants his daughter to marry the smartest of 3 extremely intelligent young princes, and so the king's wise men devised an intelligence test.
The princes are gathered into a room and seated, facing one another, and are shown 2 black hats and 3 white hats. They are blindfolded, and 1 hat is placed on each of their heads, with the remaining hats hidden in a different room.
The king tells them that the first prince to deduce the color of his hat without removing it or looking at it will marry his daughter. A wrong guess will mean death. The blindfolds are then removed.
You are one of the princes. You see 2 white hats on the other prince's heads. After some time you realize that the other prince's are unable to deduce the color of their hat, or are unwilling to guess. 
What color is your hat?

Pirates and gold

Five pirates discover a chest full of 100 gold coins. The pirates are ranked by their ages. Pirate 5 is 50 years old, Pirate 4 is 49, and so on down to Pirate 1. To divide up the loot, they agree on the following:
The most senior pirate will propose a distribution of the booty. All pirates will then vote, including the most senior pirate, and if at least 50% of the pirates on board accept the proposal, the gold is divided as proposed. If not, the most senior pirate is murdered. Then the process starts over with the next most senior pirate until a plan is approved.
All Pirates are equally intelligent and selfish. Their preference is first to remain alive, and next to get as much gold as possible and finally, if given a choice between otherwise equal outcomes, to have fewer pirates on the boat.
Assume you are the senior most pirate in the group. Come up with a plan that maximizes your gold, and others will accept. How will you divide the coins?

Count 000...s

Factorial of a number 'a' is defined as:

    a! = a x (a-1) x ... x 2 x 1

How many trailing zeroes are there in 100! (100 factorial) ?

Farmer Wolf-Goat-Cabbage problem

A farmer is returning from market, where he bought a she-goat, a wolf and cabbage. On the way home he must cross a river. His boat is little, allowing him to take only one of the three things. He can’t keep the she-goat and the cabbage together (because the she-goat would eat it), nor the she-goat with the wolf (because the she-goat would be eaten). How shall the farmer get everything on the other side (without any harm)?

2 egg puzzle

* You are given 2 eggs.
* You have access to a 100-storey building.
* Eggs can be very hard or very fragile means it may break if dropped from the first floor or may not even break if dropped from 100 th floor.Both eggs are identical.
* You need to figure out the highest floor of a 100-storey building an egg can be dropped without breaking.
* Now the question is how many drops you need to make. You are allowed to break 2 eggs in the process.

25 Horses problem

You have 25 horses. When they race, each horse runs at a different, constant pace. A horse will always run at the same pace no matter how many times it races.

You want to figure out which are your 3 fastest horses. You are allowed to race at most 5 horses against each other at a time. You don't have a stopwatch so all you can learn from each race is which order the horses finish in.

What is the least number of races you can conduct to figure out which 3 horses are fastest?

1 2 3 4 5 6