Puzzles, riddles, logical questions, and lateral thinking questions are an integral part of any programming job interviews. I missed to include some puzzles when I shared my list of top 30 programming interview questions earlier, and a couple of my friends requested to share some puzzles as well. These puzzles and lateral thinking questions are mostly collected from various Java programming interviews on Investment banks, but they are equally useful for any programming job interviews. I have seen more puzzles and logical questions at junior level i.e. 2 to 4 years. These kinds of puzzles, if asked at the beginning of the interview, can make or break the interview. It’s not easy to solve them, especially when you see them the first time, but what is surely not to do is give up without a try, even if you can't think of an answer, try to show rational approach. Remember it's OK if you don't answer any puzzle question, but your approach towards unknown problem get noticed.At the same time lateral thinking questions offers several answers, and you can give your own explanation as well, but make sure it must look genuine and seems logical. Puzzles and riddles also forms a big chunk of Microsoft and Google Interview questions as well, and they are some really nasty and tough to answer. Anyway, I have not provided answers of these puzzles and logical questions, so that you can at least give it a try. Immediate answers kill the purpose of puzzles and riddles, and it's fun to solve them by yourself. By the way, you can easily find answers of these puzzles using Google, as they have asked numerous times on various programming interviews on software and technology companies.

10 puzzles, riddles, logical and lateral thinking question

Here is my list of 10 riddles, puzzles, logical and lateral thinking questions. Try to solve it by yourself before searching for answers in Google, they are not that tough or difficult. Easy answers spoils purpose of puzzles, so don’t look at them, until you are going for interview very next day.

1) There are 27 coins and a two-pan balance. All coins has same weight except for one, which is heavier than all others. All coins looks identical. What is the minimum number of weighing required to certainly find out heavier coin?

2) There are two sticks which takes one hour to burn from one end to other. The sticks do not burn at a constant rate i.e. some part may burn faster than others. You need to measure 45 minutes by using these two sticks and a lighter.

3) Two persons are walking into a railway tunnel. Upon crossing 2/3rd of the tunnel, they saw train is coming from opposite direction. Each person ran for a different end of tunnel with speed of 10 km per hour. Fortunately, both persons escaped from the tunnel just right time i.e.. at the time train would have run through them. Assuming train was running with a constant speed and both persons reacted immediately, Find out speed of train.

4) There are thee switches outside of a closed room to operate three different light bulb inside the room. You can only go into the room once and you need to determine which switch belongs to which bulb. Just to make it clear, room is perfectly locked and its not possible to determine whether lights are on from outside the room.

5) You have 10 Jars filled with marbles. Each marble weighs 10 gm, except one Jar which contains defective marbles which weighs 9 gm. Given a scale to weigh, How do you find Jar with defective marbles in just one measurement. Here scale is modern day electronic scale to measure weight.

6) A person shoots her wife. Then holds her under water for 5 minutes. Finally, he hangs her. But after 10 minutes they both go out together and enjoy a wonderful dinner together. How can this be?

7) A father and son are going in a car and suddenly there car met accident. Father died on the spot but the child rushed to the hospital. When he arrives in the hospital, doctor says, "I can't operate on this child, he is my son!" How can this be?

8) You have a 5 liter Jug and a 3 liter Jug and unlimited supply of water. You need to measure exactly 4 liter of water but there is no measuring instrument or cup. Also Jugs are oddly shaped and doesn't contain any mark.

9) There are Four people needs to cross the bridge during night. The bridge can hold the weight of two people at a time and can not be crossed without a torch. Each person walk with different speed, first can cross the bridge in 1 minutes, second in 2 minutes, third in 5 minutes and fourth take 10 minutes to cross the bridge. If two persons go together, they walk with the speed of slower person. What is the least amount in which all four people cross the bridge.

10) A person's age is many days as his father's age in weeks and as many month as his grand father's age in years. If you combine age of all three it comes 120 years. What is the age of all three?

That's all on this list of top 10 puzzles, riddles, logical questions and lateral thinking questions asked in programmer interviews. These question has maximum impact when programmer doesn't heard about it, and it means they may appear differently in actual interview. As a candidate, you can prepare all these question to get your mind working and knowing some techniques to solve them, but be prepare for surprise in actual Interview. Key of solving puzzles, logical questions or riddles are keeping your cool and not panicking. Even if you don't know answer you should start explaining your way and logic and if you have any answer which is out of box then better say it. Many times it happen when candidates are selected even if they don't solve the puzzles but in the process show some promise.

Answers 1. require 3 weighing step 1 take 9 each on each side of balance eliminate the two sets ;remaining 9 step 2 take 3 each on each side of balance eliminate the two sets; remaining 3 step 3 take 1 each on each side of balance eliminate the two sets

2. burn 1st stick from both sides and second from one side. When 1st stick finishes(half an hr) ,ignite the other end of second stick.

3.

4. switch on switch one and two. then turn two off. After entering the room, one bulb will be on(switch one). one bulb will be hot and off(switch 2) and the third will be off and cool

5.take one marble from jar one, two from jar two, three from jar three etc... and weigh.total weight if all jar contained 10 g each should be 550. Subtract the actual weight from 550, and that will be the index of the jar(eg, if 5th jar contain 9 g marbles, then total weight would be 545; 550-545=5(5th jar)

6.

7. the Doctor is the mother of the boy

8.fill the three-litter jug with water and pour it into the five-litter jug. Repeat. one litter will be left over in the three-litter jug. Empty out the five-littr jug and pour in the one litter. Now just fill the three-litter jug again and pour it into the five-litter jug. . (Mathematically, this can be represented 3 + 3 - 5 + 3 = 4)

Answer to Question 1 : Key here is to understand that 27 is cube of 3, which means it will take minimum 3 weighing attempts to find defective coin. Let's assume defective coin is heavier than normal coins, now divide 27 coins into group of 9. Out of three groups, weigh two of them in balance. The group with heavier coin, will go down, which means you can discard two groups right that time. Now further divide those 9 coins into 3 groups of 3 coins, and repeat the process, this will give you a group of 3 coins, now divide them into group of 1 coins, at this time (which is third weighing attempt), you will find out exactly which coin is defective. This puzzle can be generalized further, e.g. if interviewer gives you 8 coins or 64 coins

@Anonymous, Answer of puzzle 4 is very easy. You can keep one bulb on for couple of minutes and then switch that off and on another switch. Now you can go into room, the one, which is hot is associated with previous switch you pressed, current bulb is the switch you just pressed and the remaining third one is, well you know.

At the moment when train enters the tunnel, the first runner runned 1/3 of the tunnel and safely escaped. The second runner runned 1/3 of tunnel in oposite direction, so he has another 1/3 of tunnel to run when the train has complete tunnel length to pass. The time is equal, so we have t1=t2, meaning third of tunnel lenght devidid by 10km/h is equal as complete tunnel lenght devided by the train speed. That means train speed is 3 times more than 10km/h

1) Completely fill 5 liter Jug with water.2) Pour water from 5 litter Jug to 3 liter Jug, which means you will left with 2L of water.3) Now empty 3L jug and pour 2L into them. Now your 3L jug contains 2L of water and 5L jug is empty.

4) Now refill 5L jug and pour into 3L jug which contains 2L water already. Once you fill 3L jug, you will left with 4L of water in 5L jug.

Ahh, lots of juggling but I think this answer the puzzle number 8, anyone has better answers, I mean less steps?

ans 3; train speed is 30 kmphv=d/t first u have to caliculate the time to travel from the 1/3 of the tunnel to one person who travelled towards to train is 10=(1/3)/t from this equation u will get t value is 1/30 hrs and now should go the second person who is the running away from the train.(1/v)=(1/3)/10 from this equation u will get the v value means train speed is 30 kmph

first switch on any switch from those 3 and keep it ON for 15 mins and then switch it off . Now switch on any other switch and keep it ON ,Now you enter the room .Touch any one of the bulbs ,if any of those are hot means it belongs to the first switch you turned on and then off . The second bulb is already ON so you know the switch implicitly. The third bulb was always off so you know its switch.

Answer to question 7. The doctor is the father of the dead person. the dead person's son brings him to the hospital immediately after the accident. Grand father is the doctor, father is the dead person. His son remains alive.

Ans to question 81)fill up the 3 lit jug and pour it into the empty 5 lit jug2)now again fill up the emptied 3 lit jug and pour it to the earlier filled 5 lit jug3)so now you have 1 L remaining in the 3 lit jug4)now empty the 5 lit jug and pour the 3lit jug containing 1l water5)now again fill up the 3 lit jug and pour it into the 5 lit jug already containing 1 lit of water.6)now it finally adds upto 4 lit

Q1 I thinked about binary search and reached 4 tests. But it can find the heavier coin at 1st test.

Test 1:Put 2 sets of 13 coins each pan. If set1 = set 2, the coin that's left out is the heavier. Else eliminate 14 coins (the lighter set and the coin tha's left out). The heavier set is X.

Test 2: divide the set X in 2 sets of 6 coins each and test w/one coin left out.If set X.1 = set X.2, the coin that's left out is the heavier. Else eliminate 7 coins (the lighter set and the coin tha's left out). The heavier set is now Y.

Test 3: divide the set Y in 2 sets of 3 coins each and test w/one coin left out.If set Y.1 = set Y.2, the coin that's left out is the heavier. Else eliminate 4 coins (the lighter set and the coin tha's left out). The heavier set is now Z.

Test 4: test 2 coins of set Z.If coin Z.1 = coin Z.2, the coin that's left out (Z.3) is the heavier.

"A person shoots HER wife. Then holds her under water for 5 minutes. Finally, HE hangs her"

I thought the typo with her instead of his was intentional to suggest that it was a married lesbian couple. One woman actually shot and drowned her wife, then HE (the man she was having an affair with) came in and hanged her. Then those two went out to dinner after finishing the job.