Tuesday 1 September 2026

Quant interview

Fifty boxes each and the whole crew walks free

medium · Information, deduction and strategy puzzles

One hundred prisoners are numbered 1,…,100. In a room stand 100 opaque boxes, also numbered 1,…,100. Slips bearing the numbers 1,…,100 are placed one per box according to a permutation σ drawn uniformly at random from all 100! arrangements; slip k sits in box σ−1(k), i.e. box j contains slip σ(j).

The prisoners are led in one at a time. Each may open at most 50 boxes, look inside, and must then leave the room exactly as he found it, communicating nothing to those who follow. If every prisoner opens the box containing his own number, the whole group is freed; if even one fails, all are executed.

Before the first prisoner enters, the group may agree on a strategy. During the trial there is no communication and no observation of who has gone before. Assume each prisoner can condition his choices only on his own number and on what he sees in the boxes he opens.

  1. Exhibit a strategy and describe precisely, in terms of the permutation σ, the event on which it succeeds. Explain why the strategy makes success depend only on the cycle structure of σ.
  2. Compute the exact probability that the group is freed under your strategy.
  3. Give the limiting success probability as the number of prisoners 2m→∞ (with each allowed to open half the boxes).
Solution

The strategy

Every prisoner uses the same rule, keyed to his own number. Prisoner i opens box i first. He reads the slip σ(i) inside; if it is his own number i he is done, otherwise he opens box σ(i) next, reads σ(σ(i)), opens that box, and so on. He follows the chain i→σ(i)→σ2(i)→⋯ for up to 50 steps.

The naive alternative — each prisoner opens 50 boxes at random — gives success probability (1/2)100≈8×10−31, and it is tempting to conclude the situation is hopeless. The whole point is that a fixed random search treats the prisoners' fates as independent, whereas the cycle-following rule couples them to a single global event.

Why cycle-following works

Under this rule the sequence of boxes prisoner i opens is exactly the forward orbit of i under σ. Since σ is a permutation of a finite set, that orbit is the cycle of σ containing i, and the box holding slip i is the box σ−1(i) — the element that maps to i, i.e. the predecessor of i on its own cycle. Following i→σ(i)→⋯ eventually returns to i, and the step just before returning lands on box σ−1(i), which contains slip i.

Hence prisoner i finds his slip on some step, and he reaches it within 50 openings iff the cycle containing i has length at most 50. This is the step a candidate misses: the individual success events, one per prisoner, all reduce to statements about the same object, the cycle lengths of σ.

Therefore {all freed}={σ has no cycle of length>50}.

Exact probability for 100 prisoners

A permutation of 100 elements can have at most one cycle of length exceeding 50, since two such would need more than 100 elements. So the failure event is a disjoint union over L=51,…,100 of "σ has a cycle of length exactly L."

Count permutations of {1,…,n} with a distinguished cycle of length L: choose the L members in (nL) ways, arrange them in a cycle in (L−1)! ways, and permute the remaining n−L arbitrarily in (n−L)! ways: (nL)(L−1)!(n−L)!=n!L. With n=100, the probability of having a cycle of length exactly L>50 is n!/Ln!=1L. Summing the disjoint cases, ℙ(fail)=∑L=511001L=H100−H50, where Hn=∑k=1n1/k. Thus ℙ(freed)=1−∑L=511001L=1−(H100−H50). Numerically H100−H50≈0.688172, so the group survives with probability ℙ(freed)≈0.311828.

The limit

For 2m prisoners each opening m boxes, the same argument gives ℙ(freed)=1−∑L=m+12m1L=1−(H2m−Hm). Since H2m−Hm=∑k=m+12m1k→∫01dx1+x=ln2 (a Riemann sum for 1/(1+x)), limm→∞ℙ(freed)=1−ln2≈0.306853.

Remarks. The success probability stays bounded away from 0 no matter how many prisoners there are — the striking feature of the puzzle. It is also a theorem (Curtin–Warshauer) that no strategy beats the cycle-following one, so 1−(H100−H50) is the optimal survival probability, not merely one achievable value.

Final answers. (1) Follow the cycle from your own box; the group is freed iff σ has no cycle longer than 50. (2) 1−(H100−H50)≈0.3118. (3) 1−ln2≈0.3069.

Statistics in machine learning

The primal-dual witness and a sign-dependent recovery threshold

hard · High-dimensional regression, the lasso and sparse recovery

Consider the linear model y=Xβ*+w∈ℝn, with deterministic design X∈ℝn×p whose columns are normalized so that ‖Xj‖22=n for all j, and noise w~N(0,σ2In). Fix λ>0 and let β^∈\argminβ∈ℝp\{12n‖y−Xβ‖22+λ‖β‖1\}. Write S=supp(β*), s=|S|, Σ^=X⊤X/n, and assume Σ^SS≻0.

(a) State the subgradient stationarity (KKT) conditions. Construct the primal-dual witness (PDW) candidate that is forced to be supported on S. Prove that if the induced dual vector satisfies the strict feasibility condition ‖z^Sc‖∞<1, then every optimal solution of the lasso is supported in S and equals the constructed candidate (i.e. the solution is unique). Point out precisely where Σ^SS≻0 is used.

(b) Derive the explicit expression for z^Sc in terms of w and the blocks of Σ^. Assuming the irrepresentable (mutual incoherence) condition \|Σ^ScSΣ^SS−1sign(βS*)\|∞≤1−γ,γ∈(0,1], give a sufficient condition on λ (and the required lower bound on minj∈S|βj*| for the signs to be preserved) guaranteeing exact sign recovery with high probability, and show that λ≍σlogp/n suffices.

(c) Now take p=3, S={1,2}, the noiseless case w=0, β*=(3,2,0)⊤, and Σ^=(10c01ccc1). (i) For which c is Σ^≻0? (ii) Determine the exact set of pairs (c,λ) with λ>0 for which the lasso recovers sign(β*) exactly. (iii) Show that if the nonzero signs had been (+,−) instead of (+,+), the admissible range of c would be strictly larger, and explain the mechanism.

Solution

(a) The primal-dual witness and uniqueness

Since the objective is convex, β^ is optimal iff there is a subgradient z^∈∂‖β^‖1 with 1nX⊤(Xβ^−y)+λz^=0, where z^j=sign(β^j) if β^j≠0 and z^j∈[−1,1] if β^j=0. Substituting y=Xβ*+w and writing Δ^=β^−β*, stationarity becomes Σ^Δ^−1nX⊤w+λz^=0.($\star$)

The witness. We impose β^Sc=0 (so Δ^Sc=0) and z^S=sign(βS*), then solve (⋆) block-wise and finally check that the solution is genuinely feasible. The S-block of (⋆) gives Δ^S=Σ^SS−1(1nXS⊤w−λz^S), which uses invertibility of Σ^SS. The Sc-block defines the remaining dual coordinates, z^Sc=1λ(1nXSc⊤w−Σ^ScSΔ^S). The construction succeeds if (i) sign(β^S)=sign(βS*) (so that z^S was a valid subgradient) and (ii) ‖z^Sc‖∞≤1.

The uniqueness step (the one candidates skip). Suppose ‖z^Sc‖∞<1 strictly, and let β~ be any optimum with subgradient z~. The map β↦12n‖y−Xβ‖22 is strictly convex in the fitted value Xβ, and ‖·‖1 is convex; hence over the (convex) optimal set the fitted vector Xβ~ is constant. Therefore 1nX⊤(y−Xβ~) is constant across optima, so by (⋆) the subgradient λz~ is the same for every optimum — in particular z~=z^, our constructed dual vector. Now use complementary slackness: at optimum ⟨z~,β~⟩=‖β~‖1, i.e. ∑j(z~jβ~j−|β~j|)=0. Each summand is ≤0, and for j∈Sc we have |z~j|=|z^j|<1, forcing β~j=0. Thus every optimum is supported in S. Finally, XSβ~S=XSβ^S and XS has full column rank (again because Σ^SS≻0), so β~S=β^S. The optimum is unique and equals the witness. ◻

Thus Σ^SS≻0 enters twice: once to solve for Δ^S, once to pass from equal fitted values to equal coefficients.

(b) Explicit dual vector and the scaling of λ

Substituting Δ^S into the formula for z^Sc, z^Sc=Σ^ScSΣ^SS−1sign(βS*)⏟incoherence term+1λ[1nXSc⊤w−Σ^ScSΣ^SS−11nXS⊤w]⏟=:1λΠw. The incoherence term is bounded by 1−γ by hypothesis. So strict feasibility holds provided the noise term satisfies ‖Πw‖∞≤λγ (then ‖z^Sc‖∞≤1−γ+γ=1, and one takes <γ for strictness).

Each coordinate of Πw is a mean-zero Gaussian. Its variance is bounded by the variance of 1nXj⊤w (projection reduces variance), which is σ2‖Xj‖22/n2=σ2/n by the normalization. A maximum over ≤p Gaussians of variance ≤σ2/n obeys, with probability ≥1−2p−1, ‖Πw‖∞≤2σlogpn. Hence it suffices to choose λ≥2σγlogpn,i.e. λ≍σγlogpn. For the signs to be preserved we need Δ^S=Σ^SS−1(1nXS⊤w−λsign(βS*)) small in sup-norm relative to the signal; a sufficient condition is minj∈S|βj*|>\|Σ^SS−1\|∞(λ+1n‖XS⊤w‖∞), the β-min condition. Under both, part (a) gives exact sign recovery with probability ≥1−2p−1.

(c) The concrete design

(i) Positive definiteness. Leading minors of Σ^ are 1, 1, and detΣ^=1(1−c2)−0+c(0−c)=1−2c2. So Σ^≻0⟺|c|<1/2.

(ii) Exact recovery region. Here Σ^SS=I2, so Σ^SS−1=I2, Σ^ScS=(c, c), and sign(βS*)=(+1,+1). Noiseless, so Πw=0.

Both requirements are strict, and |c|<1/2 already guarantees Σ^≻0. Therefore  exact sign recovery⟺|c|<12  and  0<λ<2.  At the boundaries recovery fails: |c|=12 gives z^3=±1 (non-strict, solution can be non-unique with a spurious third coordinate), and λ≥2 kills the second coordinate.

(iii) The sign mechanism. With signs (+,−) the incoherence term becomes z^3=(c,c)(1,−1)⊤=c−c=0, which is strictly feasible for every c in the PD range |c|<1/2. So the same design recovers the support for |c|<1/2≈0.707, strictly larger than the |c|<1/2 of the (+,+) pattern. The reason: the off-support column X3 correlates equally (c) with X1 and X2; when the two active coordinates carry opposite signs their pulls on the dual coordinate cancel, whereas equal signs add. Irrepresentability is genuinely a property of the signed support, not just the support.

Closing note. The textbook mutual-incoherence constant maxz∈{±1}s‖Σ^ScSΣ^SS−1z‖∞ takes the worst case over signs; here that worst case is 2|c|, giving the pessimistic threshold |c|<1/2. The tempting error is to treat that worst-case number as the recovery threshold for a given β*. For a fixed signed support only the actual sign vector matters, and — as (+,−) shows — the true threshold can be much more generous.


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