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 the 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 trial, even if you can't think of an answer, try to show a 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 form 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 to 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 to these puzzles using Google, as they have asked numerous times on various programming interviews on software and technology companies.

Also, basic knowledge of essential data structure and algorithms is also very important and that's why I suggest all Java programmers join a comprehensive Data Structure and Algorithms course like

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 trial, even if you can't think of an answer, try to show a 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 form 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 to 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 to these puzzles using Google, as they have asked numerous times on various programming interviews on software and technology companies.

Also, basic knowledge of essential data structure and algorithms is also very important and that's why I suggest all Java programmers join a comprehensive Data Structure and Algorithms course like

**Data Structures and Algorithms: Deep Dive Using Java**on Udemy to improve your knowledge and algorithms skills.##
__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.**Further Learning**

The Coding Interview Bootcamp: Algorithms + Data Structures

Data Structures and Algorithms: Deep Dive Using Java

Algorithms and Data Structures - Part 1 and 2

## 48 comments :

In Question6, Is he a Photographer?

@Kapil, that's correct mate. Good answer. He is photographer, here shot means taking photos :)

@Jarvin why don't you make another blog post with just the answers? I couldn't find the answer for question 3 anywhere...

tRain -> [A, B, C] <- tunel

A = B = C, A+B+C = 3A = 3B = 3C

Time T0 = 0

persons P1 and P2 are between A, B, tRain is far away.

Time T1 = t

Person P1 is out of the tunel right in time. tRain is at the start of the tunel. Person P2 is between B and C

Time T2 = 2t

Person P2 made it out of the tunle right in time. tRain is at the end of the tunel.

S = V*T (s = length, v = speed, T = time)

For person P1

A = 10*T

for Person P2

B = 10*t <==> C = 10*t <==> A = 10*t

B + C = 10*2t <==> 2A = 10*2t <==> A = 10t

for Train

A + B + C = x*t <==> 3A = x*t

From P1 or from p1 we can get

A = 10*t

t = A/10

And this we will put in equation of train

3A = x*(A/10)

3A = xA/10

3 = x / 10

30 = x

x = 30 km/h

What is the answer for question 4 and 5?

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)

9. 17 minutes

A(1) and B(2) cross the bridge, takes 2 mins

B comes back takes 2 mins(total 4)

C(5) and D(10) cross the bridge takes 10 mins (total 14)

A comes back take 1 min (total 15)

A and B cross the brodge again takes 2 mins (total 17 mins)

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.

Please correct me if I am wrong.

For the third question, I think the speed of train is 30 km/h.

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

Answer of Questions 8:

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?

Answers to 10. 6 years, 42 years and 72 years. classic Solve the equations with three variables problem...

answer for 7th is.....

doctor is childs mother.

answer for 6 is

He is taking and developing a photograph of his wife.

answer to first question is 1.

They asked the minimun no of measures. Keep one aside and weigh 13 each on two pans. If they balance out, you have the answer

fill up the 5 liter jug and 3 litre jug to its half portion..that is 2.5 + 1.5=4litres ...thats it

ya 30kmph is correct for quest 3...

gns

Fill the 3lit jug and pour water into 5 liter.again fill 3lt and pour water into 5 liter.

So 1 lt is left in 3lt.

Throw the water from 5lt.and fill the 1lt water in 5lt.now again fill 3lt and pour in 5 lt.

1+3=4...done

ans 3; train speed is 30 kmph

v=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

answer of the 3 one is 30 kmph

Q6 says a person shooted HER wife. Then later , it says HE hang her. So i think that the he and her are two different people and the two of them went for dinner. This is just my opinion.

Number 9 should be 12 mins.

first A(1) and B(2) cross the bridge in 2 mins

then C(5) and D(10) cross the bridge in 10 mins.

Nobody said there was only one torch.

answer of question4

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.

Ans. of Que 10 .

child's age 6 years

father's age 42 years

grand father's age 72 years

This does not proof that three is the minimum, only that it is possible in three times, so it does not solve the problem

Answer to Puzzle 7

The Father from Church travels with a son who is not his biological son!

Answer to Puzzle 7

May be the child and father hit a church father.And may be that doctor is actual mother of the church father.

Answer to Question No 3:

Let Length of tunnel = x

When they saw the train, distances to the ends of tunnel: x/3 and 2x/3

Time taken (TT) by 2x/3 person = TT by train to reach the first end + TT by the train inside the tunnel

Time taken (TT) by 2x/3 person = TT by x/3 person + TT by the train inside the tunnel

ie (2x/3)/10 = (x/3)/10 + x/Y (time = distance/velocity: Y = train speed)

2/30 = 1/30 + 1/Y

Y = 30 Km/Hr

Answer to Qustion No 1 is 4

1. 13, 13. Remaining 1

2. 6, 6. Remaining 1

3. 3,3. Remaining 0

4. 1,1. Remaining 1

Answer to Question No 4. Switch on first switch. Wait for 2 minutes. Switch on second switch. Go inside the room and touch the bulbs to find out which bulb belongs to which 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.

in ques. 9 ans is 12 min

A[1] AND B[2] IT WILL TAKE 2 MIN

C[5] AND D[10] IT WILL TAKE 10 MIN

TOTAL 12 MIN

answer for q no. 1 is 3 attempts, we can find the odd coin..

9 & 9 keep 9 on other side,

if blnc take 9 frm other side, balance 3& 3 keep 3 aside,

if balance take 3 frm other side , balance 1 & 1,keep 1 aside.

now u got the odd one out..

Q7

Ans:- The person in the car is Church Father :)

Ans to question 8

1)fill up the 3 lit jug and pour it into the empty 5 lit jug

2)now again fill up the emptied 3 lit jug and pour it to the earlier filled 5 lit jug

3)so now you have 1 L remaining in the 3 lit jug

4)now empty the 5 lit jug and pour the 3lit jug containing 1l water

5)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

Q3) person in the car is grand father

Q6) It is a picture of his wife,he did a photoshoot of her,developed the pic by keeping it under water and then hung the picture for display and later went out with her for dinner.

Q5 is quite easy (more elegant solution than previously proposed)

As already said, we take "n" marbles from jar "#n" (1 from jar 1, 2 from jar 2, ..)

If you take a look at the multiplication table for 9, you will notice a nice property

for the last digit:

1x9 = 9

2x9 = 18

3x9 = 27

4x9 = 36

5x9 = 45

6x9 = 54

7x9 = 63

8x9 = 72

9x9 = 81

10x9 = 90

The last digit is inverse to the factor:

3x9 = 27 --> 3 (factor) = 10 (inverse to) - 7 (last digit)

And since any sum of any multiples of 10 (20 = 2*10, 30 = 3*10, ..) wont

change the last digit, we can assume that the jar with the 9g marbles is:

10 -

jar 1 yields 9

jar 2 yields 8

jar 3 yields 7 and so on..

(Programmatically the last digit is just the result of mod 10)

They're irregularly shaped.

1. 9,9. Remaining 9

2. 3,3. Remaining 3

3. 1,1. Remaining 1

Yes, finally someone who doesn't think it's 3. It can be done another way too though. Take 2 coins and put them on the scales. If 1 side is heavier, you have yourself an answer!!!

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.

I was sure I had 6 but now I feel like an idiot.

"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.

Wow. I'm glad that was not my interview question.

In the best case the minimum number of weighing is 1, 13/13 if scales equal remaining coin is defective/heavier/lighter

6. The person shoots with camera, holds the photo into the water,hangs it and then went for dinner with his wife.

1) use bubble search

number 8

#1) 3 litters 2 times to 5 litters

#2) 3 litters will get 1 litter.

#3) 3 litters's 1 litter move to 5 litters.

#4) full 3 litter move to 5 litters, and (1+3) is 4

3 is the minimum attempt that guarantee the solution... otherwise it could be just random picking that doesn't guarantee u will be right

1st one is wrong

## Post a Comment