Gambler’s ruin, for quant interviews
The fair case is a one-line answer. The interviewer is really testing whether you can set the walk up cleanly, solve the biased case from the recurrence instead of guessing, and feel how violently a small edge compounds.
For candidates practicing random walks with absorbing barriers · Updated July 21, 2026
Set the walk up before you solve it
Strip away the story — chips, a random-walking stock, a token bouncing between barriers — and every gambler’s-ruin question is the same object: an integer state doing a random walk between two absorbing walls at and . Each step is with probability and with probability . The single number that runs the whole problem is the ratio .
Before writing anything, say out loud what you are solving for: the hitting probability (which wall do you reach first?) or the expected duration (how many steps until you hit one?). Both come from the same recurrence, and mixing them up is the fastest way to lose the room.
The fair walk is a straight line
Let be the probability of ruin — hitting before — starting from . Conditioning on the first step gives the recurrence with boundaries and . When this says is the average of its neighbours, i.e. the sequence is linear:
Starting from with a target of : ruin , reach . No exponentials, no fuss — and a clean sanity check that the boundaries give and .
The biased walk: solve the recurrence
For the linear shortcut is wrong, and reaching for it is the classic trap. Treat as a linear recurrence and try . That gives the characteristic equation
since the discriminant is , a perfect square. The general solution is with ; the boundaries , pin down and :
As you have , the two roots collide, and L’Hôpital collapses this straight back to . That limit is the check that proves you derived the right thing rather than pattern-matched a formula.
How fast a small edge becomes fatal
Ruin depends on against , so a bias does not nudge the answer — it compounds geometrically with distance. Take , so , from the same start of out of :
so ruin is about 95.8%, up from in the fair game. A ten-point shift in the per-step odds nearly doubled your chance of losing everything.
This is the intuition an interviewer wants you to carry out of the room: against the house, the barrier you want is exponentially far away and the barrier you fear sits right behind you. Distance from ruin buys you almost nothing once the walk is biased.
Expected duration is a second recurrence
“How long does the game last?” uses the same first-step conditioning, but with a for the step you just took: , . In the fair case this telescopes to a clean product,
which peaks dead center: from , you expect steps, and the mid-point tops out at . The biased duration carries the terms and is shorter and skewed — the drift keeps flushing you toward ruin instead of letting the walk meander.
Watch the sign: with the formula stays positive. A negative or zero expected time off the boundary means your recurrence is broken.
The infinite-horizon limit
A favorite follow-up: drop the upper wall () and ask whether you are ruined for sure. Send in the ruin formula. If then , , and — certain ruin, no matter how rich you start. If then and you survive forever with probability
American roulette makes it concrete: an even-money bet wins with , a edge, so . Trying to double from to units succeeds only about 1 in 37,000 of the time. The edge is small; the wall is not.
Variants that change the answer
The result is a fact about how the walk moves, so listen for a tweak that changes the mechanics:
- Ties / lazy walk. Add a “stay put” probability . It divides both and by , leaving the ratio — and therefore every ruin probability — unchanged. Only the expected duration stretches, by roughly .
- Bold play. With the odds against you, small even bets guarantee slow ruin; betting boldly toward the target minimizes the number of unfavorable bets and maximizes your reach probability. Timid play is the trap.
- Reflecting barrier. If bounces you back instead of absorbing, it is no longer a ruin problem at all — the boundary condition changes and so does the whole answer. Always confirm each wall is absorbing before you reuse the formula.
Common mistakes
- Using on a biased walk. The linear answer is a special case. If the prompt gives any edge, you owe the formula.
- Dropping the in duration. Expected time counts the step you just took; forget it and you get zero everywhere. Boundary is what makes the recurrence solvable.
- Assuming a tiny edge barely matters. Because ruin scales with , a couple of percent per step becomes near-certain ruin over any real distance. Say so — it is the finance-relevant punchline.
- Confusing ruin with reach. They sum to , but interviewers ask for a specific one. State which wall your is measuring and check both boundaries.
Practice the pattern
Gambler’s ruin is the anchor of a whole family: absorbing walks, hitting probabilities, expected stopping times. The skill is setting the recurrence up cleanly and knowing when the fair shortcut is a trap. Drill that on the random-walk and absorbing-barrier questions in the LeetQuidity curriculum, or take the free calibration to see where your reasoning breaks under time.