Quant Memo
Core

The Coupon-Collector Problem

Collecting the last few missing coupons dominates the total time, because each new coupon gets harder to find as the collection fills up — the expected total scales as n times the harmonic number of n.

Prerequisites: How to Attack a Brainteaser

Cereal boxes each contain one of nn equally likely collectible toys, chosen independently at random each time. How many boxes, on average, do you need to buy before you have all nn toys? The intuition "about nn boxes" is badly wrong — the real answer grows noticeably faster, and the reason why is the useful part.

Setting it up with linearity of expectation

Break the collection into stages. Say you're in "stage ii" for as long as you have exactly i1i-1 distinct toys and are waiting for a new one (a toy you don't already have). Stage 1 runs from the start until your first toy. Stage nn is the wait for the very last missing toy.

Each stage is a geometric wait. In stage ii, you already have i1i-1 of the nn toys, so each new box is a "success" (a toy you don't have) with probability ni+1n\dfrac{n-i+1}{n}. The expected number of boxes to wait for one success, when each trial succeeds with probability qq, is 1/q1/q. So the expected length of stage ii is nni+1\dfrac{n}{n-i+1}.

Add up the stages. Total expected boxes =i=1nnni+1=n(1n+1n1++11)=nHn= \sum_{i=1}^{n} \dfrac{n}{n-i+1} = n\left(\dfrac{1}{n} + \dfrac{1}{n-1} + \cdots + \dfrac{1}{1}\right) = n \cdot H_n, where HnH_n is the nn-th harmonic number.

Worked example

With n=50n=50 distinct toys, how many boxes do you expect to need to complete the set?

H50ln50+0.5773.912+0.577=4.489H_{50} \approx \ln 50 + 0.577 \approx 3.912 + 0.577 = 4.489. Expected boxes 50×4.489224\approx 50 \times 4.489 \approx 224. Completing a set of 50 needs roughly 224 boxes on average — more than four times the naive guess of 50 — because the last few missing toys are each individually rare events once most of the set is already collected.

expected wait per stage, first toys fast, last toys slow stage: 1st toy -> ... -> last toy (n/1 boxes expected)
Early toys arrive almost every box; the last few missing toys each take, on average, a large fraction of the whole collection size to find.

Total expected time equals the sum of n/(ni+1)n/(n-i+1) over all stages, which is nHnn(lnn+0.577)n \cdot H_n \approx n(\ln n + 0.577). The harmonic sum grows slowly, but multiplied by nn it means completing the last item costs roughly as much as nn boxes by itself — the tail dominates, not the start.

When an interviewer asks "expected time until every one of nn things has happened at least once (with equal, independent probability each trial)," reach straight for nHnn H_n instead of simulating — it's a fixed formula, not a case-by-case puzzle.

The same tail-dominated shape shows up whenever a strategy needs to "see everything at least once" — testing every code path, sampling every rare regime in a backtest, or a market maker needing every symbol in a universe to trade at least once before a model is fully calibrated. The last few cases are always disproportionately expensive.

Related concepts

Practice in interviews

Further reading

  • Motwani & Raghavan, Randomized Algorithms (ch. 3)
ShareTwitterLinkedIn