Interview Puzzles
15 Must-Know Puzzles โ The ones that separate thinkers from guessers. Master the logic, own the interview.
25 Horses Puzzle
Hard Classic 4 minProblem Statement
You have 25 horses and a racetrack that allows 5 horses to race at a time. You have no stopwatch โ you can only see the relative order of finish. What is the minimum number of races needed to find the top 3 fastest horses?
Step-by-Step Solution
Race all 25 horses in groups of 5 โ 5 races
Label groups A, B, C, D, E. In each group, rank horses 1-5 (A1 is fastest in group A).
Race the 5 group winners โ 1 race (Race 6)
Race A1, B1, C1, D1, E1. Say the result is: A1 > B1 > C1 > D1 > E1
Eliminate horses that can't be in top 3
D1 and E1 lost to 3+ horses โ eliminated. All of D and E groups โ eliminated. C3, C4, C5 โ eliminated (C1 is at best 3rd, so C3+ can't be top 3). B3, B4, B5 โ eliminated. A4, A5 โ eliminated.
Final race with remaining candidates โ 1 race (Race 7)
A1 is definitely #1 (no need to race). Race: A2, A3, B1, B2, C1. Top 2 from this race = 2nd and 3rd overall.
After 6 races, only 5 horses remain as candidates for 2nd and 3rd place.
Key Insight
The trick is elimination by logic, not brute force. After the winners' race, you can eliminate 19 horses without racing them again. The diagonal pattern shows: horses below and to the right of position 3 in the grid can't possibly be top 3.
Common Mistake
Don't include A1 in the 7th race โ it's already proven to be #1. Racing it again wastes a slot. Also, don't forget B2 โ it could potentially beat B1 in a direct race (we only know B1 beat other group winners, not that it beat B2 overall).
Variations
What if we need to find only the fastest horse?
What if we need to find top 5?
8 Ball Puzzle
Medium Classic 3 minProblem Statement
You have 8 identical-looking balls. One is slightly heavier than the others. Using a balance scale, what's the minimum number of weighings to find the heavy ball?
Step-by-Step Solution
Divide into 3 groups: (3, 3, 2)
Key insight: divide by 3, not 2. This gives more information per weighing.
Weigh 3 vs 3 (Weighing 1)
If one side is heavier โ heavy ball is in those 3. If balanced โ heavy ball is in the remaining 2.
If heavy ball is in group of 3: weigh 1 vs 1 (Weighing 2)
If one side heavier โ that's it. If balanced โ third ball is heavy.
If heavy ball is in group of 2: weigh 1 vs 1 (Weighing 2)
Heavier one is the answer.
Key Insight
A balance scale has 3 outcomes: left heavy, right heavy, or balanced. So you can distinguish 3 possibilities per weighing. With 2 weighings: 3ยฒ = 9 possibilities โ enough for 8 balls. With binary thinking (divide by 2), you'd need 3 weighings.
- n balls โ โlogโ(n)โ weighings needed
- For 8 balls: โlogโ(8)โ = โ1.89โ = 2
Variations
12 balls, one is different (heavier OR lighter), find it in 3 weighings
What's the maximum number of balls for N weighings?
Competitive Edge
The generalization: with k weighings, you can identify one defective among 3^k items (if you know it's heavier). This is called the ternary search principle. Mentioning this shows mathematical thinking beyond the specific puzzle.
Bridge and Torch
Medium Classic 3 minProblem Statement
Four people need to cross a bridge at night. They have one torch, and the bridge can hold only 2 people at a time. The torch must be carried on every crossing. Each person walks at different speeds: 1 min, 2 min, 5 min, 10 min. When two cross together, they move at the slower person's pace. What's the minimum total time to get everyone across?
The Optimal Strategy
1 and 2 cross together โ 2 min
1 returns with torch โ 1 min
5 and 10 cross together โ 10 min
This is the key insight โ send the two slowest together!
2 returns with torch โ 2 min
1 and 2 cross together โ 2 min
Total: 2 + 1 + 10 + 2 + 2 = 17 minutes
Key Insight
The counter-intuitive idea: send the two slowest people together. This way, you "pay" for the 10-minute person only once. The naive approach (always having fastest person escort everyone) gives: 2+1+5+1+10 = 19 minutes โ worse!
- Naive approach: 1 escorts everyone โ 2 + 1 + 5 + 1 + 10 = 19 min
- Optimal: slow people together, fast people ferry torch โ 17 min
Common Mistake
The intuition "fastest person should always carry the torch back" is WRONG for this puzzle. It's more efficient to have the two fastest make an extra crossing so that the two slowest can cross together.
Variations
What if there are N people?
Water Jug Problem
Medium 3 minProblem Statement
You have a 3-liter jug and a 5-liter jug. You have unlimited water supply. Measure exactly 4 liters.
Step-by-Step Solution
| Step | Action | 3L Jug | 5L Jug |
|---|---|---|---|
| 1 | Fill 5L jug | 0 | 5 |
| 2 | Pour 5L โ 3L (fill 3L) | 3 | 2 |
| 3 | Empty 3L jug | 0 | 2 |
| 4 | Pour 5L โ 3L (2 liters) | 2 | 0 |
| 5 | Fill 5L jug | 2 | 5 |
| 6 | Pour 5L โ 3L (only 1L fits) | 3 | 4 โ |
Key Insight
Any amount that's a multiple of GCD(3,5) = 1 can be measured. Since GCD is 1, you can measure ANY integer amount up to 5 liters. The operations form a mathematical system: you're essentially computing 5a + 3b = target where a and b are integers (can be negative, representing emptying).
target % GCD(jug1, jug2) == 0 AND target <= max(jug1, jug2)
Variations
4L and 6L jugs, measure 2L?
4L and 6L jugs, measure 3L?
100 Prisoners Problem
Hard 4 minProblem Statement
100 prisoners are numbered 1-100. There are 100 boxes, each containing a random prisoner's number. Each prisoner can open at most 50 boxes. They must find their own number. All must succeed for everyone to go free. They can strategize beforehand but cannot communicate once started. What strategy maximizes survival probability?
The Loop Strategy
Prisoner N starts by opening box N
If box N contains number M, open box M next
Continue following the chain until finding own number
This will ALWAYS find their number eventually โ the question is: in 50 boxes or less?
Why This Works
The box-number arrangement forms cycles (permutation loops). Each prisoner is guaranteed to be in exactly one cycle. If you start at your number and follow the chain, you'll eventually return to yourself. The strategy succeeds if ALL cycles have length โค 50.
- Random strategy: (1/2)^100 โ 0.0000...% (impossible)
- Loop strategy: P(no cycle > 50) โ 31.18%
- Math: 1 - ln(2) โ 0.3069 in the limit
Numbers in boxes form closed loops. Each prisoner follows their loop.
Competitive Edge
The mathematical beauty: probability of survival = 1 - H_100 + H_50 โ 1 - ln(2) as nโโ, where H_n is the harmonic number. This connects to random permutation cycle statistics โ a deep area of combinatorics. Mentioning this shows serious mathematical depth.
Common Mistake
Thinking "31% is bad" โ compared to (1/2)^100 โ 10^-31, it's astronomically better! There's no strategy that can do better than ~31%. Also, this is NOT a trick question โ the loop strategy is genuinely optimal.
Egg Dropping Puzzle
Hard Classic 4 minProblem Statement
You have 2 identical eggs and a building with 100 floors. There's a critical floor F: eggs break when dropped from floor F or above, and survive below F. Find F with minimum worst-case drops.
The Optimal Strategy
First egg: Drop at floors 14, 27, 39, 50, 60, 69, 77, 84, 90, 95, 99, 100
Notice: gaps decrease by 1 each time (14, 13, 12, 11, ...)
When first egg breaks, use second egg to linear search the gap
If egg 1 breaks at floor 14, search floors 1-13 one by one (13 more drops).
Total drops = position of first break + gap size = always 14
Drop at 14 (1 drop) + break โ search 1-13 (13 drops) = 14 total. Drop at 14 OK, drop at 27 (2 drops) + break โ search 15-26 (12 drops) = 14 total. Pattern continues!
Key Insight
If first drop is at floor X, and egg breaks, you need X-1 more drops (linear search). If it survives, you've "used up" 1 drop, so next gap should be X-1. This gives: X + (X-1) + (X-2) + ... + 1 โฅ 100. Solving: X(X+1)/2 โฅ 100 โ X โฅ 14.
min_drops = โ(-1 + โ(1 + 8N)) / 2โ
// For k eggs and N floors (DP relation):
dp[k][n] = 1 + min(max(dp[k-1][x-1], dp[k][n-x])) for x in 1..n
Variations
What if you have 3 eggs and 100 floors?
What if you have infinite eggs?
Common Mistake
Binary search (drop at 50, then 25 or 75, etc.) doesn't work with only 2 eggs. If the egg breaks at 50, you have 1 egg left and must check floors 1-49 one by one โ 50 drops worst case! The constraint of limited eggs fundamentally changes the strategy.
Competitive Edge
This is a classic DP problem. In coding interviews, you might be asked to write the code. State: dp[eggs][floors] = minimum drops. Transition: try each floor, take min of max(break case, survive case). Time: O(knยฒ), can be optimized to O(kn log n) with binary search on transition.
Coin Flip Problems
Medium 3 minProblem: Fair Result from Biased Coin
You have a biased coin (not 50-50). How can you generate a fair 50-50 outcome?
Solution: Von Neumann Extraction
Flip the coin twice
If HT โ call it "Heads". If TH โ call it "Tails".
If HH or TT โ discard and repeat.
Why It Works
If P(H) = p, then: P(HT) = p(1-p) and P(TH) = (1-p)p. These are equal! So HT and TH have the same probability, making the choice between them fair. HH and TT are discarded.
More Coin Problems
Expected flips to get first Head?
Expected flips to get HH (two heads in a row)?
Which comes first on average: HH or HT?
Poisoned Bottle Puzzle
Hard Classic 3 minProblem Statement
You have 1000 bottles, exactly one is poisoned. You have 10 test strips that change color if exposed to poison (one-time use). You can put multiple drops on each strip. How do you find the poisoned bottle in one round of testing?
Solution
Number bottles 0-999 in binary (10 bits)
Bottle 0 = 0000000000, Bottle 1 = 0000000001, ..., Bottle 999 = 1111100111
Each strip corresponds to one bit position
Strip 1 = bit 0, Strip 2 = bit 1, ..., Strip 10 = bit 9
Put drop from bottle N on strip K if bit K of N is 1
Bottle 5 (binary 0000000101) โ drops on strips 1 and 3
Read which strips changed โ that binary number is the poisoned bottle
If strips 1, 3, 5 changed โ binary 00000101010 = bottle 42 is poisoned
Key Insight
This is information theory in action. With 10 strips, you have 2^10 = 1024 possible outcomes (each strip is either positive or negative). That's enough to uniquely identify one bottle among 1000. You're essentially encoding bottle numbers in binary and using strips as bits.
- N bottles need โlogโ(N)โ strips
- 1000 bottles: โlogโ(1000)โ = 10 strips
Variations
What if poison takes time to show and you have limited time?
What if 2 bottles are poisoned?
Pirate Gold Division
Hard 4 minProblem Statement
5 pirates (ranked by seniority: A > B > C > D > E) must divide 100 gold coins. The most senior pirate proposes a division. All pirates vote. If majority accepts (โฅ50%), division happens. Otherwise, proposer is thrown overboard and next pirate proposes. Pirates are rational, want maximum gold, and prefer others die if it doesn't affect their gold. What does Pirate A propose?
Solution: Backward Induction
Case: Only D and E remain
D proposes 100-0. D votes yes (50% = pass). D gets everything, E gets 0.
Case: C, D, E remain
E knows he gets 0 if D proposes. So E accepts any offer โฅ 1 from C. C proposes 99-0-1. C+E vote yes (majority).
Case: B, C, D, E remain
D gets 0 if C proposes. So D accepts โฅ 1 from B. B proposes 99-0-1-0. B+D vote yes (50% = pass).
Case: All 5 pirates
C gets 0 if B proposes. E gets 0 if B proposes. A only needs to buy 2 votes. A offers 1 coin each to C and E. They accept (better than 0). A proposes 98-0-1-0-1. A+C+E vote yes (60%).
Key Insight
Backward induction: work from the smallest case (2 pirates) to the full case. At each step, figure out who gets 0 in the next scenario โ those pirates will accept 1 coin now to avoid getting 0 later. The proposer only needs to "buy" enough votes to reach majority.
Common Mistake
Thinking pirates would form alliances or that "fairness" matters. Pirates are purely rational โ they only care about their own gold. Also, the "prefer death" assumption matters: if A offers C 0 coins and C is indifferent, C votes NO (prefers A to die).
Variations
What if there are 6 pirates?
What if >50% is required (strict majority)?
Clock Angle Problem
Easy 2 minProblem Statement
What is the angle between the hour hand and minute hand at 3:15?
Solution
Minute hand position: 15 minutes = 15 ร 6ยฐ = 90ยฐ from 12
Minute hand moves 360ยฐ/60min = 6ยฐ per minute
Hour hand position: 3 hours + 15 minutes = 3.25 hours = 3.25 ร 30ยฐ = 97.5ยฐ from 12
Hour hand moves 360ยฐ/12hr = 30ยฐ per hour = 0.5ยฐ per minute
Angle = |97.5ยฐ - 90ยฐ| = 7.5ยฐ
angle = |30รH - 5.5รM|
// If > 180ยฐ, subtract from 360ยฐ for acute angle
if (angle > 180) angle = 360 - angle
Key Insight
The tricky part: hour hand moves continuously, not just on the hour. At 3:15, the hour hand is NOT at the 3 โ it's 1/4 of the way toward 4. Hour hand speed: 0.5ยฐ per minute. Minute hand speed: 6ยฐ per minute.
Variations
At what times are the hands exactly overlapping?
At what times are the hands at 90ยฐ?
Train Crossing Problems
Medium 3 minProblem 1
Two trains, 100 km apart, travel toward each other. Train A goes 30 km/h, Train B goes 20 km/h. A bird flies at 50 km/h between them, starting from Train A, bouncing back and forth until trains meet. How far does the bird fly?
Solution (The Smart Way)
Time until trains meet: 100 km รท (30 + 20) km/h = 2 hours
Combined approach speed = 50 km/h
Bird flies for 2 hours at 50 km/h = 100 km
Don't calculate each leg โ just total time ร bird speed!
Key Insight
The trap is trying to calculate each back-and-forth trip of the bird โ that's an infinite series! The clever solution: the bird flies the ENTIRE time the trains are moving, so just find the total time and multiply by bird's speed. (Story: Von Neumann allegedly solved this instantly; when told "you found the trick!", he replied "What trick? I summed the series.")
More Train Problems
A 200m train crosses a 300m bridge. Train speed is 50 km/h. How long to cross?
Two trains of lengths 100m and 150m cross each other traveling opposite directions at 40 km/h and 50 km/h. Time to cross?
River Crossing Puzzles
Easy Classic 3 minProblem: Farmer, Wolf, Goat, Cabbage
A farmer must cross a river with a wolf, a goat, and a cabbage. The boat holds only the farmer + one item. If left alone: wolf eats goat, goat eats cabbage. How does everyone cross safely?
Step-by-Step Solution
| Step | Action | Left Bank | Right Bank |
|---|---|---|---|
| Start | โ | F, W, G, C | โ |
| 1 | Take Goat โ | W, C | F, G |
| 2 | Return alone โ | F, W, C | G |
| 3 | Take Wolf โ | C | F, W, G |
| 4 | Bring Goat back โ | F, G, C | W |
| 5 | Take Cabbage โ | G | F, W, C |
| 6 | Return alone โ | F, G | W, C |
| 7 | Take Goat โ | โ | F, W, G, C โ |
Key Insight
The goat is the problem child โ it can't be left with either wolf or cabbage. So the goat must travel more than others. The counter-intuitive step: bringing the goat back (step 4). Sometimes you have to "undo" progress to make overall progress.
Variations
3 missionaries and 3 cannibals crossing (boat holds 2)
Jealous husbands (3 couples, boat holds 2, no woman alone with another man)
Dice Probability Questions
Medium 3 minProblem 1: Sum of Two Dice
What's the probability of getting a sum of 7 when rolling two fair dice?
Key Insight
Total outcomes: 6 ร 6 = 36. Ways to get 7: (1,6), (2,5), (3,4), (4,3), (5,2), (6,1) = 6 ways. P(sum=7) = 6/36 = 1/6. Note: 7 is the MOST likely sum (6 ways), while 2 and 12 are least likely (1 way each).
More Dice Problems
Expected value of a single die roll?
Expected number of rolls to see all 6 faces?
Roll until you get a 6. Expected rolls?
Probability at least one 6 in four rolls?
Competitive Edge
For expected value of "roll until condition" problems, use the formula: E = 1/p where p is probability of success. For "expected to collect all N items": E = N ร H_N where H_N is the N-th harmonic number. These patterns appear repeatedly in interviews.
Monty Hall Problem
Medium Classic 3 minProblem Statement
You're on a game show. There are 3 doors: behind one is a car, behind the others are goats. You pick a door (say #1). The host, who knows what's behind each door, opens another door (say #3) revealing a goat. He then asks: "Do you want to switch to door #2?" Should you switch?
Why Switching Wins
Initial pick: 1/3 chance of car, 2/3 chance of goat
Host's action doesn't change YOUR door's probability
Your door is still 1/3. The other two doors together are still 2/3.
Host eliminates one goat door, concentrating 2/3 on the remaining door
The "2/3 probability" that was split between two doors is now ALL on the one remaining door.
In 2 out of 3 equally likely scenarios, switching wins. Host always opens a goat door.
Key Insight
The host's action is NOT random โ he MUST open a goat door. This gives you information. If you initially picked a goat (2/3 chance), the host is FORCED to reveal the other goat, and switching gets you the car. If you initially picked the car (1/3 chance), switching loses. Switching wins 2/3 of the time!
Common Mistake
Thinking "Now there are 2 doors, so it's 50-50." This ignores that the host's choice was constrained. The host had information and used it. Your original choice was uninformed (1/3). The remaining door inherits the 2/3 probability that was on "the other doors."
Variations
What if there are 100 doors and host opens 98?
What if the host opens doors randomly (might reveal the car)?
Logical Deduction Puzzles
Hard 4 minProblem: Two Guards (Heaven/Hell)
You're at a fork. One path leads to heaven, one to hell. Two guards stand there: one ALWAYS lies, one ALWAYS tells truth. You don't know who's who. You can ask ONE question to ONE guard to find the path to heaven. What do you ask?
Why It Works
If you ask the truth-teller:
He truthfully reports what the liar would say. The liar would point to hell. So truth-teller points to hell.
If you ask the liar:
He lies about what the truth-teller would say. Truth-teller would point to heaven. Liar lies and points to hell.
Both guards point to HELL. Take the other path!
Key Insight
The trick is to create a double negation. By asking about what the OTHER guard would say, you force a lie to be applied exactly once (either the guard you ask lies, or they truthfully report a lie). One lie = wrong answer. So the answer is always wrong, and you take the opposite.
More Logic Puzzles
Blue Eyes Puzzle: 100 people, some have blue eyes. Everyone can see others' eyes but not their own. If you have blue eyes, you must leave. A visitor says "I see someone with blue eyes." On day 100, all 100 blue-eyed people leave. Why?
3 people with hats (2 black, 3 white available). Each sees others' hats but not own. First two say "I don't know my color." Third (blind) says "I know mine!" How?
Sum and Product puzzle: "I don't know the numbers." "I knew you wouldn't." "Now I know." "Now I do too." Find the numbers.
Competitive Edge
Logic puzzles test your ability to think recursively about what others know. Key concepts: Common knowledge (everyone knows X, and everyone knows everyone knows X, etc.) vs mutual knowledge (everyone knows X, but might not know others know). The Blue Eyes puzzle is specifically about the difference. Also know about meta-reasoning: "If they could deduce X, they would have said so. They didn't, so they couldn't, which tells me Y."