Monday 31 August 2026

Quant interview

Filling every bin: mean, spread, and the last stretch

medium · Coupon collector and occupancy problems

A market-data feed emits ticks. Each tick carries exactly one of n distinct symbols, and the symbols are independent across ticks, each equally likely (1/n). Let T be the number of ticks until every one of the n symbols has appeared at least once.

  1. Show that 𝔼[T]=nHn, where Hn=∑k=1n1k. Set up the decomposition you use carefully.

  2. Using the same decomposition, find Var(T) in closed form and give its leading asymptotic as n→∞. Comment on the ratio of the standard deviation to the mean. Evaluate the mean, variance, and standard deviation for a fair die (n=6).

  3. Suppose that at some moment you have observed exactly k distinct symbols (with 0≤k<n). Find the expected number of additional ticks needed to complete the set, and explain why this expectation does not depend on which k symbols you already hold. Evaluate it for n=6, k=4.

Solution

The decomposition that unlocks everything

Write T=X0+X1+⋯+Xn−1, where Xi is the number of ticks needed to go from i distinct symbols to i+1 distinct symbols. Once you already hold i symbols, each new tick is a new symbol with probability

pi=n−in,

and a repeat otherwise, independently of the past (the ticks are i.i.d. and only the count i matters, not which symbols). Hence Xi is geometric on {1,2,…} with success probability pi.

The point a candidate can miss: the segments X0,…,Xn−1 are mutually independent. After each success the process restarts as a fresh sequence of i.i.d. Bernoulli(pi+1) trials whose length is unaffected by how long the previous segment took (memorylessness of the geometric plus i.i.d. draws). This independence is what makes the variance a plain sum.

Part 1: the mean

A geometric(p) variable has mean 1/p, so

𝔼[T]=∑i=0n−11pi=∑i=0n−1nn−i.

Substituting j=n−i (so j runs 1 to n),

𝔼[T]=n∑j=1n1j=nHn.

For n=6: H6=1+12+13+14+15+16=2.45, so 𝔼[T]=6·2.45=14.7.

Part 2: the variance

By independence, Var(T)=∑i=0n−1Var(Xi). A geometric(p) variable has variance (1−p)/p2. With pi=(n−i)/n we have 1−pi=i/n and pi2=(n−i)2/n2, so

Var(Xi)=i/n(n−i)2/n2=ni(n−i)2.

Summing and substituting j=n−i again,

Var(T)=∑i=0n−1ni(n−i)2=∑j=1nn(n−j)j2=n2∑j=1n1j2−n∑j=1n1j.

Thus the closed form is

Var(T)=n2∑j=1n1j2−nHn.

Since ∑j≥1j−2=π2/6 and Hn=lnn+O(1), the leading term is

Var(T)~π26n2(n→∞).

So the standard deviation is ~π6n, of order n, while the mean is of order nlnn. The ratio sd/𝔼~π6lnn→0: T concentrates around nlnn, and the tail beyond the mean is dominated by the long wait for the single last symbol (that segment alone contributes variance n(n−1)≈n2).

For n=6: ∑j=16j−2=1+14+19+116+125+136=1.49139, so

Var(T)=36·1.49139−14.7=53.690−14.7=38.99,sd(T)≈6.24.

Part 3: the remaining stretch

Given that exactly k symbols have been seen, the future is again a fresh collector problem: the remaining waits are the independent geometrics Xk,Xk+1,…,Xn−1 with success probabilities pj=(n−j)/n. Hence

𝔼[additional ticks]=∑j=kn−1nn−j=n∑i=1n−k1i=nHn−k.

It depends only on how many symbols remain, n−k, not on their identities: by symmetry every unseen symbol is drawn with the same probability 1/n per tick, so relabelling the missing symbols changes nothing. For n=6, k=4 (two symbols missing):

nHn−k=6H2=6(1+12)=9.

Answers

  1. 𝔼[T]=nHn; for n=6, 𝔼[T]=14.7.
  2. Var(T)=n2∑j=1nj−2−nHn~π26n2; for n=6, Var(T)≈38.99 and sd(T)≈6.24. The relative spread sd/𝔼→0.
  3. Expected additional ticks =nHn−k; for n=6, k=4 this equals 9.

Closing note. The tempting error is to treat the Xi as merely uncorrelated, or worse to try computing 𝔼[T2] directly — the whole simplification rests on the independence of the segments, which is genuinely true here. As a cross-check on Part 1, one can also use 𝔼[T]=∑m≥0ℙ(T>m) together with the inclusion–exclusion occupancy formula ℙ(T>m)=∑k=1n(−1)k+1(nk)(1−kn)m; summing the geometric series in m collapses back to nHn.

Statistics in machine learning

When the bootstrap chokes on a maximum

medium · The bootstrap: validity and failure modes

Let X1,…,Xn be i.i.d. from the Uniform(0,θ) distribution, θ>0 unknown. Write Mn=maxiXi=X(n), the maximum likelihood estimator of θ. Assume throughout that the Xi are almost surely distinct.

1. Show that the exact sampling distribution of the normalized error satisfies Tn:=n(θ−Mn)θ →d Exp(1).

2. Now form the ordinary (full-sample) nonparametric bootstrap: conditionally on the data, draw X1\*,…,Xn\* i.i.d. from the empirical distribution on {X1,…,Xn}, let Mn\*=maxiXi\*, and let Tn\*:=n(Mn−Mn\*)Mn be the bootstrap analogue of Tn. Compute the conditional probability P\*(Mn\*=Mn) exactly and give its limit. Deduce that the bootstrap law of Tn\* cannot converge to Exp(1), and identify the precise obstruction.

3. Consider instead the m-out-of-n bootstrap: draw X1\*,…,Xm\* i.i.d. from the empirical distribution, with m=mn→∞ and m/n→0. With Mm\*=maxi≤mXi\* and Tm\*:=m(Mn−Mm\*)/Mn, show that the offending atom disappears and that the conditional law of Tm\* recovers Exp(1) in probability.

Solution

1. The exact target law

For t∈[0,n], using F(x)=x/θ on [0,θ] and independence, P(Tn>t)=P(Mn<θ(1−t/n))=(F(θ(1−t/n)))n=(1−tn)n. This →e−t for every fixed t≥0, so Tn→dExp(1). The limit is continuous: P(T=0)=0. Keep that fact; it is what the bootstrap will violate.

2. Why the full-sample bootstrap fails

Conditionally on the data, each Xi\* equals the maximizing observation with probability 1/n. The bootstrap maximum equals Mn iff that observation is drawn at least once, so P\*(Mn\*=Mn)=1−(1−1n)n ⟶ 1−e−1≈0.632. Whenever Mn\*=Mn we have Tn\*=0. Hence the bootstrap law of Tn\* carries a point mass at 0 whose size tends to 1−e−1.

This is the decisive observation. The Kolmogorov distance between the bootstrap CDF Gn\* and the target G(t)=1−e−t satisfies supt|Gn\*(t)−G(t)| ≥ Gn\*(0)−G(0)=P\*(Tn\*=0) → 1−e−1>0, because G is continuous with G(0)=0. So the bootstrap is inconsistent: no matter the realization of the data, its law stays a fixed distance from Exp(1).

The deeper reason (worth seeing). Compute the whole conditional survival function. With Kn(t):=#{i:Xi>Mn(1−t/n)}, P\*(Tn\*>t)=P\*(Mn\*<Mn(1−t/n))=(1−Kn(t)n)n. The window (Mn(1−t/n),Mn] has width Θ(1/n), so it contains only a bounded number of order statistics; in fact n(θ−X(n−j))/θ converge jointly to the arrival times of a rate-1 Poisson process, and Kn(t)→dN(t), the count of that process on (0,t] (with N(t)≥1 once the max is inside). Therefore P\*(Tn\*>t) →d e−N(t), a random limiting survival function. Consistency (Bickel–Freedman) requires the conditional law to converge to the fixed Exp(1); here it converges to a random measure. The atom e−N(0+)·-mass =1−e−1 is just the visible symptom. The general lesson: the bootstrap fails exactly when the statistic depends on the extreme tail of the empirical measure, where resampling cannot manufacture the missing continuum.

3. Why m-out-of-n repairs it

Repeat the atom computation with m draws: P\*(Mm\*=Mn)=1−(1−1n)m=1−exp(mlog(1−1/n))≈1−e−m/n ⟶ 0, since m/n→0. The atom vanishes.

For the full law, Tm\*>t iff all m resampled points fall in [0,Mn(1−t/m)]. Now the window (Mn(1−t/m),Mn] has width ≈θt/m, which is large compared with the 1/n spacing since m/n→0. So the empirical measure of the window is accurate: by Glivenko–Cantelli and Mn→θ, P\*(Mm\*<Mn(1−t/m))=(Fn(Mn(1−t/m)))m,Fn(Mn(1−t/m))→P1−tm (to leading order). Hence P\*(Tm\*>t) ≈ (1−tm)m →P e−t. The subsampling ratio m/n→0 is exactly the condition that (i) kills the atom and (ii) makes the relevant window wide enough for the empirical CDF to be trustworthy. With m=o(n) and m→∞ the m-out-of-n bootstrap is consistent.

Answer

  1. Tn→dExp(1), a continuous law.
  2. P\*(Mn\*=Mn)=1−(1−1/n)n→1−e−1≈0.632; the bootstrap law of Tn\* has an atom of this mass at 0 and its conditional survival function converges to the random limit e−N(t) (rate-1 Poisson N), so it cannot converge to the continuous Exp(1) — the ordinary bootstrap is inconsistent for the maximum.
  3. Taking m→∞, m/n→0 sends the atom to 0 and yields P\*(Tm\*>t)→Pe−t, restoring consistency.

Tempting wrong answer: concluding the bootstrap works because Mn\*→θ and Mn→θ. Consistency of the point estimate says nothing about consistency of the distribution of the normalized error; the O(1/n)-scale behavior at the boundary is where everything happens, and that scale is precisely what a full-sample resample cannot reproduce.


Two new problems every morning at 8am · every day so far