Puzzles are patterns in disguise
Interviewers reuse a small number of ideas with new numbers and new stories. Recognising the idea is most of the work. This lesson covers four families: waiting for patterns, races between events, backward induction, and optimising a schedule.
Waiting for a pattern
Expected waiting times for coin patterns are solved by first-step analysis on "how much of the pattern is matched". For two heads in a row, with the expected flips from scratch and after a single head:
which gives .
There is also a shortcut for a fair coin. For each such that the first symbols of the pattern equal its last symbols (including = the full length), add :
Self-overlap makes a pattern slower to appear. After a near miss, an overlapping pattern often has to start again from little progress, while a non-overlapping one keeps the progress it had. For a die, replace with : two sixes in a row takes rolls on average.
Worked example
waiting for HTHT
A fair coin is flipped until HTHT appears. What is the expected number of flips?
Show solutionHide solution
Compare prefixes with suffixes:
- : H vs T, no.
- : HT vs HT, yes, contributing .
- : HTH vs THT, no.
- : the whole pattern, contributing .
So the expected wait is , compared with for a non-overlapping four-flip pattern such as HHTT.
Races between events
"Which happens first?" questions are solved by ignoring everything irrelevant. If each trial produces with probability , with probability , and otherwise nothing, then
because only the first trial that is or matters. For alternating turns, condition on the first round: if player 1 wins on a turn with probability , then , so it equals .
For races between patterns, set up states as before, but with two absorbing states instead of one.
Backward induction
For games between rational players, solve the smallest case first and work up. Each player compares their offer with what they would get if the game moved to the next, smaller case.
In the pirate game with the "at least half the votes" rule:
- Two pirates (D, E). D votes for their own plan, which is half the votes, so D keeps everything: .
- Three pirates (C, D, E). C needs one more vote. E gets 0 if C is thrown overboard, so E accepts 1 coin: .
Each extra pirate buys the votes of those who would get nothing in the next case, paying one coin more than that next case would give them. Keep going and you can solve any number of pirates.
Optimising a schedule
For crossing puzzles (the bridge, boats, lamps), write down the two or three candidate strategies and compare totals, rather than searching blindly. For the bridge with crossing times , the two ways to get the slowest pair over are:
- Fastest pair shuttles: cross; returns; cross; returns; cross. Total .
- Fastest escorts each: escorts , returns, escorts , returns, crosses with . Total .
The first is better exactly when : the two slow people should cross together when the second-fastest is fast enough to make the extra return trip cheap.
Worked example
four people, times 1, 3, 6 and 8
Using the rules above, what is the minimum time to get people with crossing times 1, 3, 6 and 8 minutes across?
Show solutionHide solution
Shuttle: . Escort: . Since , shuttling wins, and the answer is 18 minutes.
Knowledge check
What is the expected number of fair coin flips until three heads in a row (HHH)?
Knowledge check
You roll two dice repeatedly. What is the probability that a sum of 7 appears before a sum of 6?
Knowledge check
Two players alternate shooting free throws, each scoring with probability 1/3. The first to score wins. What is the probability that the first shooter wins?
Practice problems
Finished reading?
Answer the 3 knowledge checks to complete this lesson (0 done).