The Hundred Prisoners and the Boxes
A strategy that turns a hopeless-looking one-in-a-million search into roughly a coin flip, by making every prisoner follow the same permutation-cycle rule instead of searching independently.
Prerequisites: How to Attack a Brainteaser
This is one of the most famous puzzles in quant interviewing, precisely because the naive probability is so bad and the actual answer is so good that most candidates assume they've made an arithmetic error.
The puzzle
100 prisoners, numbered 1 to 100. A room contains 100 boxes, also numbered 1 to 100, each containing one prisoner's number, placed by a random permutation unknown to the prisoners. Each prisoner, one at a time, may open up to 50 boxes, looking for their own number, then the room is reset exactly as they found it before the next prisoner enters. No communication after the process starts. All 100 prisoners must find their own number for everyone to survive. Is there a strategy giving a decent chance of success, and if so, how good?
The naive approach fails badly. If each prisoner opens 50 boxes at random, each one succeeds with probability . But the prisoners need all 100 to succeed, and independent 50% chances multiply: , a number smaller than one in a trillion trillion. This looks hopeless.
The strategy: follow the cycle. Each prisoner starts by opening the box matching their own number. Whatever number they find inside, they open that numbered box next, and repeat, always opening the box named by the number they just found, up to 50 boxes. This isn't random — it's following the permutation's own structure.
Why it works. Any permutation of 100 items decomposes into disjoint cycles. If prisoner is in a cycle of length , starting at box and following the chain always returns to box after exactly steps — and crucially, that chain passes through every box in 's own cycle before repeating. So prisoner finds their number within 50 boxes if and only if the cycle containing has length at most 50. All 100 prisoners succeed exactly when no cycle in the permutation is longer than 50 — and since a 100-element permutation can have at most one cycle longer than 50 (two such cycles wouldn't fit), this reduces to one clean question about one number.
The number. The probability a random permutation of 100 elements has no cycle longer than 50 works out to roughly — about 31%. That's a wildly different outcome from one-in-a-trillion-trillion, achieved purely by coordinating on structure instead of searching independently.
Turning independent random search into a shared, structure-following rule can convert an astronomically bad probability into a merely disappointing one. The cycle strategy doesn't change any individual's 50% odds — it makes everyone's success or failure the same event, tied to one shared random quantity (the longest cycle) instead of 100 separate coin flips.
The classic mistake is treating "each prisoner has a 50% chance" as independent across prisoners under the cycle strategy. It isn't — all 100 outcomes are perfectly correlated through the single permutation, which is exactly why the joint probability is 31% and not .
Related concepts
Practice in interviews
Further reading
- Winkler, Mathematical Puzzles: A Connoisseur's Collection