Quant interview prep guides

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 iii doing a random walk between two absorbing walls at 000 and NNN. Each step is +1+1+1 with probability ppp and −1-1−1 with probability q=1−pq = 1 - pq=1−p. The single number that runs the whole problem is the ratio r=q/pr = q/pr=q/p.

An absorbing random walk from 0 to NEleven states on a line. State 0 is the ruin wall and state 10 is the target wall. The walker starts at state 3 and each step moves up with probability p or down with probability q.STATE (CAPITAL)pq0123456789NRUINstart i = 3TARGET
Capital does a random walk between two absorbing walls: hit 0 and you are ruined, hit N and you cash out. Every interior step is +1 with probability p or −1 with probability q = 1 − p. Naming these four things — start, walls, and the two step probabilities — is the whole setup.

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 PiP_iPi​ be the probability of ruin — hitting 000 before NNN — starting from iii. Conditioning on the first step gives the recurrence Pi=p Pi+1+q Pi−1P_i = p\,P_{i+1} + q\,P_{i-1}Pi​=pPi+1​+qPi−1​ with boundaries P0=1P_0 = 1P0​=1 and PN=0P_N = 0PN​=0. When p=q=12p = q = \tfrac12p=q=21​ this says PiP_iPi​ is the average of its neighbours, i.e. the sequence is linear:

Pi=1−iN,P(reach N)=iN.P_i = 1 - \frac{i}{N}, \qquad \Prob(\text{reach } N) = \frac{i}{N}.Pi​=1−Ni​,P(reach N)=Ni​.

Starting from 333 with a target of 101010: ruin =7/10=70%= 7/10 = 70\%=7/10=70%, reach =3/10=30%= 3/10 = 30\%=3/10=30%. No exponentials, no fuss — and a clean sanity check that the boundaries give 111 and 000.

The biased walk: solve the recurrence

For p≠qp \neq qp=q the linear shortcut is wrong, and reaching for it is the classic trap. Treat Pi=p Pi+1+q Pi−1P_i = p\,P_{i+1} + q\,P_{i-1}Pi​=pPi+1​+qPi−1​ as a linear recurrence and try Pi=xiP_i = x^iPi​=xi. That gives the characteristic equation

p x2−x+q=0  ⟹  x∈{ 1,  qp },p\,x^2 - x + q = 0 \;\Longrightarrow\; x \in \left\{\,1,\; \tfrac{q}{p}\,\right\},px2−x+q=0⟹x∈{1,pq​},

since the discriminant is 1−4pq=(q−p)21 - 4pq = (q-p)^21−4pq=(q−p)2, a perfect square. The general solution is Pi=A+B riP_i = A + B\,r^iPi​=A+Bri with r=q/pr = q/pr=q/p; the boundaries P0=1P_0 = 1P0​=1, PN=0P_N = 0PN​=0 pin down AAA and BBB:

P(ruin∣i)=r i−r N1−r N,P(reach N)=1−r i1−r N.\Prob(\text{ruin} \mid i) = \frac{r^{\,i} - r^{\,N}}{1 - r^{\,N}}, \qquad \Prob(\text{reach } N) = \frac{1 - r^{\,i}}{1 - r^{\,N}}.P(ruin∣i)=1−rNri−rN​,P(reach N)=1−rN1−ri​.

As p→12p \to \tfrac12p→21​ you have r→1r \to 1r→1, the two roots collide, and L’Hôpital collapses this straight back to 1−i/N1 - i/N1−i/N. 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 rir^iri against rNr^NrN, so a bias does not nudge the answer — it compounds geometrically with distance. Take p=0.4p = 0.4p=0.4, so r=q/p=1.5r = q/p = 1.5r=q/p=1.5, from the same start of 333 out of 101010:

P(reach 10)=1−1.5 31−1.5 10=2.37556.665≈0.0419,\Prob(\text{reach } 10) = \frac{1 - 1.5^{\,3}}{1 - 1.5^{\,10}} = \frac{2.375}{56.665} \approx 0.0419,P(reach 10)=1−1.5101−1.53​=56.6652.375​≈0.0419,

so ruin is about 95.8%, up from 70%70\%70% in the fair game. A ten-point shift in the per-step odds nearly doubled your chance of losing everything.

Ruin probability: fair versus biasedTwo curves of ruin probability against starting state from 0 to 10. The fair line falls linearly from 1 to 0. The biased curve stays near 1 far longer before dropping, so ruin is higher everywhere.PROBABILITY OF RUIN vs STARTING STATE0%50%100%0246810starting state i96%70%88%50%fair (p = ½)biased (p = 0.4)
Ruin probability by where you start, target fixed at N = 10. Fair play (slate) is the straight line 1 − i/N. A modest edge against you, p = 0.4 so r = 1.5, bows the curve up hard: from the same start of 3, ruin climbs from 70% to almost 96%.

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 +1+1+1 for the step you just took: Di=1+p Di+1+q Di−1D_i = 1 + p\,D_{i+1} + q\,D_{i-1}Di​=1+pDi+1​+qDi−1​, D0=DN=0D_0 = D_N = 0D0​=DN​=0. In the fair case this telescopes to a clean product,

Difair=i (N−i),D_i^{\text{fair}} = i\,(N - i),Difair​=i(N−i),

which peaks dead center: from i=3i = 3i=3, N=10N = 10N=10 you expect 3⋅7=213 \cdot 7 = 213⋅7=21 steps, and the mid-point i=5i = 5i=5 tops out at 252525. The biased duration carries the rrr terms and is shorter and skewed — the drift keeps flushing you toward ruin instead of letting the walk meander.

Expected duration: fair versus biasedTwo curves of expected time to absorption against starting state. The fair curve is a symmetric arch topping out at 25. The biased curve is lower and skewed, peaking near 20.8.EXPECTED STEPS TO A WALL vs STARTING STATE01020250246810starting state i25≈ 20.8fair (p = ½)biased (p = 0.4)
Expected steps until you hit a wall. Fair play (slate) peaks at i(N − i) = 25 dead center. Bias (p = 0.4) both shortens the game and drags the peak toward the far wall — the edge keeps shoving you back toward ruin, so you rarely wander long.

Watch the sign: with q−p>0q - p > 0q−p>0 the formula Di=iq−p−Nq−p⋅1−ri1−rND_i = \tfrac{i}{q-p} - \tfrac{N}{q-p}\cdot\tfrac{1-r^i}{1-r^N}Di​=q−pi​−q−pN​⋅1−rN1−ri​ 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 (N→∞N \to \inftyN→∞) and ask whether you are ruined for sure. Send N→∞N \to \inftyN→∞ in the ruin formula. If p<12p < \tfrac12p<21​ then r>1r > 1r>1, rN→∞r^N \to \inftyrN→∞, and Pi→1P_i \to 1Pi​→1 — certain ruin, no matter how rich you start. If p>12p > \tfrac12p>21​ then r<1r < 1r<1 and you survive forever with probability

P(never ruined)=1−(qp)i.\Prob(\text{never ruined}) = 1 - \left(\tfrac{q}{p}\right)^{i}.P(never ruined)=1−(pq​)i.

American roulette makes it concrete: an even-money bet wins with p=18/38p = 18/38p=18/38, a 5.26%5.26\%5.26% edge, so r=10/9r = 10/9r=10/9. Trying to double from 100100100 to 200200200 units succeeds only about 0.9100≈0.9^{100} \approx0.9100≈ 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 sss. It divides both ppp and qqq by 1−s1-s1−s, leaving the ratio q/pq/pq/p — and therefore every ruin probability — unchanged. Only the expected duration stretches, by roughly 1/(1−s)1/(1-s)1/(1−s).
  • 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 000 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 1−i/N1 - i/N1−i/N on a biased walk. The linear answer is a p=qp = qp=q special case. If the prompt gives any edge, you owe the rir^iri formula.
  • Dropping the +1+1+1 in duration. Expected time counts the step you just took; forget it and you get zero everywhere. Boundary D=0D = 0D=0 is what makes the recurrence solvable.
  • Assuming a tiny edge barely matters. Because ruin scales with rir^iri, 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 111, but interviewers ask for a specific one. State which wall your PiP_iPi​ 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.

Take the calibrationView the curriculum

On this page

Set up the walkThe fair walkThe biased recurrenceHow an edge compoundsExpected durationInfinite horizonVariants & mistakes

Related guides

Random Walk Quant Interview GuideRandom Walk Hitting Probability Interview QuestionsRandom Walk Expected Time Interview QuestionsStopping Time Quant Interview QuestionsQuant Interview Cheat Sheet: Formulas, Identities and Fast MethodsQuant Interview Drills by Topic
LeetQuidity

The complete quant interview course.

InstitutionsCurriculumPricingFAQCalibrationDemoGuides
XLinkedInInstagramYouTube

© 2026 LeetQuidity — a W Interior company. All rights reserved.

Privacy PolicyTerms of ServiceTrust & Security