Interview puzzles are a realistic way of testing your lateral thinking in software engineer interviews. It shows the interviewer your real-world problem-solving and creative thinking skills. These puzzles are mostly popular among Tier-1 companies, which look for candidates with more than basic programming skills.
All the puzzles might not have a single solution. There may be multiple solutions, and the interviewer wants to see how you find the most efficient solution and how you think through the problem.
In this blog, we present some commonly asked interview puzzles for software engineers. We also share some tips that will help you quickly solve the puzzle and ace the interview.
Top 20 Puzzle Questions Asked in Interviews
Most of the puzzles asked in interviews are meant to test how well you can think “different.” They usually don’t have one correct answer to refer to. You can solve it using your own logic.
So, looking at 100s of puzzles online and checking their answers won’t be enough. You need to THINK on your own and actually develop an approach to solving these puzzles.
We’ve covered 20 sample puzzles to get your prep started.
Logical Interview Puzzle for Software Engineers
Logical puzzles are those types of puzzles where you might not require your programming skills. It’s based on your reasoning and logical skills. Let’s look at some logical interview puzzles for software engineers.
1. Crossing the Bridge Puzzle
Four people need to cross a bridge. It’s nighttime and pretty dark. There’s only one flashlight; it’s dangerous to cross the bridge without one. The bridge can only support two people at a time. Each person will take a different amount of time to cross the bridge: 1 min, 2 mins, 7 mins, and 10 mins. What is the shortest possible time for all four people to cross the bridge?
This puzzle is designed to test your ability to come up with the most efficient way to solve a problem, especially with constraints. This is an important skill to have for a software developer where solutions need to be as efficient as possible.
Solution:
The only way to minimize the total time is if, at all times, you can have only the two slowest people together. How could this be done? Well, one way is:
- Send the two fastest across first (1 min and 2 mins).
- One of the fastest returns with the flashlight (1 min).
- Now send the two slowest (7 mins and 10 mins) across.
- The fastest returns again (2 mins).
- Finally, send the two fastest back across (1 min and 2 mins).
This way, everyone will be able to cross the bridge in 17 minutes
Source: Puzzlefry
2. The Man in the Elevator Puzzle
A man who lives on the tenth floor of a building takes the elevator every day to go down to the ground floor to go to work or to go shopping. When he returns in the evening, he takes the elevator to the seventh floor and walks up the stairs to the tenth floor to reach his apartment.
Why does he do this? Note that if it’s a rainy day, or if there are other people in the elevator, he goes to his floor directly. Also, he hates walking.
This is a puzzle that tests your ability to think out of the box and consider real-world limitations that are usually not immediately obvious. It also leads you to pay attention to more subtle hints, such as the man taking an umbrella in rainy weather or resorting to other people for a solution to the problem.
Solution:
The problem is that he is a short man and cannot reach the button for the tenth floor. In the rain, he uses his umbrella to push the button or, if there are other people in the elevator, he requests them to push it.
He can manage to push only the button for the seventh floor, the one that he can reach. That's why he walks the rest of the way to the tenth floor when he is alone and does not have his umbrella.
3. Heaven or Hell Puzzle
You have two doors in front of you. One door leads to heaven, and the other to hell. There are two guards, one by each door. One guard always tells the truth, and the other always lies, but you don’t know who is who. You can only ask one question to one guard to find the door to heaven. What question would you ask?
This puzzle is designed to test how well you can come up with a logically consistent solution with incomplete information. This is useful in debugs or more generally when trying to understand complex systems.
Solution:
You can ask either guard, "If I were to ask the other guard which door leads to heaven, what would they say?" Then, take the opposite door. This works because:
- If you ask the truth-teller, they will truthfully tell you that the liar would point to the wrong door.
- If you ask the liar, they will lie about what the truth-teller would say, also pointing to the wrong door.
4. Three Mislabeled Jars
You have three mislabeled jars. The first jar contains apples, the second contains oranges, and the third contains a mix of apples and oranges. You need to label the jars. You can pick as many fruits as you want from each jar. What is the least number of fruits you have to pick from each jar to label them correctly?
This puzzle is designed to check your ability to solve problems in a condition when there are not enough resources and you can use only limited steps. This is usually the case with most of the optimization algorithms.
Solution:
You select only one fruit from the "mixed" labeled jar. Because all the jars are labeled incorrectly, "mixed" is actually an apple-only or orange-only jar. In this case, when an apple is drawn, it states that the jar consists of apples alone, and therefore, the "apples" labeled jar will be mixed. Similarly, the drawing of an orange would show that the jar contains only oranges.
5. Gold Bar Cut Puzzle
You have hired someone to work for you for seven days, and you have a gold bar to pay him. You must give him a piece of gold every day. What is the least number of cuts you can make to the gold bar such that you can pay them 1/7th of it each day?
This puzzle puts a focus on dynamic planning, which is important for the management of resources in software engineering.
Solution:
Make two cuts in the gold bar to divide it into pieces of 1/7th, 2/7ths, and 4/7ths. You can pay the worker as follows:
- Day 1: Give them 1/7th.
- Day 2: Take back 1/7th and give them 2/7ths.
- Day 3: Give them back the 1/7th, now they have 3/7ths.
- Day 4: Take back all and give 4/7ths.
- Day 5: Give back 1/7th, now they have 5/7ths.
- Day 6: Take back 1/7th, give 2/7ths, now they have 6/7ths.
- Day 7: Give back 1/7th for the final payment.
6. Man Fell in Well Puzzle
A man fell in a well. The well is 30 meters deep. In a day, he can climb 4 meters, but he slips down 3 meters. How many days would he take to come out of the well?
This puzzle is a test of how well you can dissect a problem with incremental progress, very similar to the iterative algorithms in programming.
Solution:
On day one the man climbs 4 meters but slips back by 3 meters resulting in a net gain of 1 meter. And so it goes on, until the 27th day when he scrambles his way from a height of 27 meters to 31 meters and gets out of the well once and for all without falling back in.
7. Bag of Coins Puzzle
You have 10 bags full of infinite coins. But one bag is full of fake coins, and you can’t remember which one. You know that a genuine coin weighs 1 gram, and a fake coin weighs 1.1 grams. How do you identify the bag containing forged coins in minimum readings?
The following puzzle is a good example of optimization under constraint, somewhat like trying to reduce complexity when designing algorithms.
Solution:
Label the bags from 1 to 10. From bag number 1, take 1 coin. From bag number 2 take 2 coins, and so on. Put them all on the scale. If all the coins were good, then the bag should have a weight that is a whole number.
The extra weight will tell you which bag is counterfeit: if it is 0.2 grams overweight, then bag 2 has the counterfeit coins; if it's 0.3 grams overweight, then bag 3 has the counterfeit coins, and so on.
8. Horses on a Race Track Puzzle
There are 25 horses and five race tracks. Find the fastest three horses among the 25 in the least number of races. This puzzle is to test your ability in prioritization, which is important in software engineering to optimize processes efficiently.
Solution:
- Step 1: Divide the horses into five groups and race each group, for a total of 5 races.
- Step 2: Take all the winners in each group and race them against each other once.
- Step 3: Now you have the fastest horse; to get the second and third fastest, pit the horses that came in second and third in the winning horse's race along with the next two fastest horses that you have timed so far.
This requires a total 7 number of races.
9. Clock Angle Puzzle
If the time is 3:15 when you look at a clock, what’s the angle between the hour hand and the minute hand?
The puzzle is a test of precision and mathematical reasoning, which is important in working with calculations and numerical constraints.
Solution:
At 3:00, the angle is 90 degrees. At 3:15, in fifteens minutes, the minute hand moves to the 3-hour mark. During this time, the hour hand has moved one-quarter of the way between 3 and 4, or by 7.5 degrees.
Thus, the angle between the hour and minute hands at 3:15 is 82.5 degrees.
10. Tomato Soup Puzzle
You have a glass of tomato soup. You have one other empty glass of a different size and shape. You have to give the soup to two children. How would you divide the soup into two glasses so that both of them are satisfied that they have got an equal share of the soup?
This puzzle tests your ability to ensure fairness and symmetry, which is important when there is a need to strike a balance in resource distribution for distributed systems.
Solution:
You can do that by pouring the soup from time to time, little by little, into each glass, first one then the other, till both reach an equal level.
Additional Logical Puzzles for Interview
Here are some additional puzzles for an interview that you can try to solve by yourself. As said earlier, there can be any number of solutions to such puzzles. You need to understand the problem and deduce the logic behind the problem to arrive at a solution.
1. Two Egg Problem
You are given 2 identical eggs and a 100-story building. And you might not be able to drop them from a specific floor or the eggs will crack. Your objective is to identify the topmost floor from which an egg can be dropped without breaking. What is the minimum number of drops you need to find the critical floor?
2. Light Bulb Switch Puzzle
In the other room, there are 3 light bulbs that the 3 switches from your first room control. The other room is entered but once. The question is simple and yet telling; can you identify which switch turns on which light bulb?
3. Poisonous Drink Puzzle
There are 1000 bottles of wine, but one of them is poisoned. You have 10 prisoners on hand to test the wine. How many tests do you need to conduct to determine which bottle contains the poison?
4. Measuring Water Puzzle
You have a 3-liter jug and a 5-liter jug. You need exactly 4 liters of water. How do you do it?
5. Weighing Marbles Puzzle
There are 9 marbles all uniform in dimensions and looks except a significantly heavier one. How will you find the heavier marble in minimum number of weighing using a balance scale?
6. Monty Hall Problem
You are a contestant on a game show and you get to choose one of three doors. Behind one door is a car and behind the other two doors are goats. After you select a door, the host, knowing what's behind the doors, opens another door revealing a goat. You get to now either stick with your original pick or switch to the remaining door. What do you do to maximize the chances of winning the car?
7. The Burning Ropes Puzzle
You are given two ropes, each of which would burn exactly 1 hour if lit continuously. However, the ropes burn in such a way that one side of each rope may burn faster than the other. Using only the two ropes and a lighter, how would you time exactly 45 minutes?
8. Spotting a Truck Puzzle
The probability of spotting a truck on a highway in an hour is 0.999. What is the probability of spotting a track on that highway in 20 minutes?
9. Batteries Puzzle
There are eight batteries, but only four of them work. You have to use them for a flashlight, which needs two working batteries. What is the minimum number of battery pairs you need to test to ensure that the flashlight is turned on?
10. Birthday Cake Puzzle
A birthday cake has to be cut into eight equal pieces in exactly three cuts. Find a way to make this cut possible.
3 Key Tips to Solve Puzzle Problems in Interviews
Yes, these puzzles are tricky. Following are 3 key tips that will ensure that you will not stumble during the interview:
1. Clarify Everything Before you Start
Don’t jump into the solution, and do not make any assumptions. If any information seems missing, ask and clarify.
2. Explain Your Process
While solving the puzzle, explain your thought process to the interviewer. It allows your interviewer to see how you plan, think, reason, and solve complex problems under pressure. Always remember — these puzzles are more about showcasing your analytical skills than finding the right solution.
3. Provide a Solution to the Puzzle: One or More!
Use your reasoning and logical skills to deduce a solution to the puzzle, even if it’s not the correct solution. You can also discuss alternate methods. It’s more about your reasoning and deducing the solution, than finding the right solution.
Fast Track your Interview Prep with Interview Kickstart!
In these times of hyper-competition, preparing for interviews is the most effective way of acing it. Interview Kickstart's Tech Interview course will help you learn different technical skills and knowledge to mail your next tech interview.
Our expert instructors will help you learn key topics around system design and data structure & algorithm, as well as a subject of your choosing such as machine learning, data science, etc. They will also guide you to write a resume that clears the application tracking system (ATS), build a strong online personal brand, and optimize your LinkedIn profile.
Read the success stories of our alumni and get inspired to join the IK revolution!
FAQs: Interview Puzzles for Software Engineers
Q1. Do We Get Asked Only Programming Puzzles in Interviews?
No. Interviewers test your ability to answer programming as well as common puzzles, which don't require programming skills.
Q.2 How to Prepare for Puzzle Questions for An Interview?
Practice multiple puzzles online, and try to solve them on your own without looking for answers. Interviewers will test your thinking abilities and insist more than getting the correct answer.
Q3. Are Puzzle Interviews Effective for Employee Selection?
Some of these calculations require significant approximations and come with unclear instructions regarding constraints. Due to their unconnected skill concentration, potential prejudice, and inability to accurately predict work performance, puzzle interviews are typically ineffective in the selection of employees.
Q.4 How Many Rounds of Interviews Do Software Engineers Have?
There are generally four to five rounds of interviews for senior roles.
Related reads: