Why heuristics
Interview puzzles are designed so that brute-force calculation is slow and a change of viewpoint is fast. Three moves cover a surprising fraction of them, and the same three moves are your best defence against a wrong answer:
- Symmetry. If several outcomes are interchangeable, they have equal probability or equal expectation. No calculation needed.
- Extremes. Push a parameter to 0, 1 or infinity, or make the problem degenerate. The answer must still make sense there, and often the extreme case is the answer.
- Small cases. Solve by hand, spot the pattern, then explain why it holds.
Symmetry, precisely
The argument is: find a transformation (relabelling, reflection, rotation) that maps the problem to itself and maps one outcome to another. Then those outcomes have the same probability. Examples:
- For i.i.d. continuous variables, each ordering is equally likely, so and any specified ordering of of them has probability .
- For i.i.d. positive , the ratios have the same distribution and sum to 1, so each has mean , whatever the distribution.
- Ants on a stick bouncing off each other behave like ants passing through each other, because the ants are indistinguishable for the question asked.
State the transformation out loud. "By symmetry" without saying what is symmetric is how wrong answers get through.
Worked example
the minimum of n uniforms by symmetry
are independent and uniform on . Find , and more generally the expected value of the -th smallest.
Show solutionHide solution
The points cut into gaps (from 0 to the smallest point, between consecutive points, from the largest point to 1). The gaps sum to 1.
Claim: the gaps are exchangeable. Put independent uniform points on a circle of circumference 1, and cut the circle at the first one to make a unit interval. The remaining points are independent uniforms on that interval, so the arcs between consecutive points on the circle are exactly our gaps. On the circle, no arc is special, so every gap has the same distribution.
Hence and
Check against the tail integral from the integration lesson: . The symmetry argument gives every order statistic at once.
Worked example
a rope around the Earth
A rope fits tightly around the equator (radius about 6,400 km). You lengthen it by 1 metre and lift it uniformly off the ground. How high does it sit?
Show solutionHide solution
Intuition says "imperceptibly". Calculation: circumference , so adding raises the radius by m, enough to crawl under.
The extreme-case shortcut. The answer does not depend on , since is linear in . If you suspected that, take the extreme : a rope of length 1 m laid in a circle has radius , so that is the gap for any planet. Letting a parameter go to a degenerate value, when you believe the answer does not depend on it, often finishes the problem.
The extreme-case check. The same move audits claimed answers. Someone asserts ; at that gives 0, but a single uniform has mean . The formula is dead in one line.
Worked example
100 lockers
100 lockers start closed. Person , for , toggles every locker whose number is a multiple of . How many lockers are open at the end?
Show solutionHide solution
Small cases. With 10 lockers, run it by hand: lockers 1, 4 and 9 end open. That suggests perfect squares.
Why. Locker is toggled once for each divisor of , so it ends open exactly when has an odd number of divisors. Divisors pair up as , and the pairing fails only when , i.e. is a perfect square. So the open lockers are : there are 10.
The order matters: the small cases gave a conjecture in a minute; the pairing argument turned it into an answer you can defend. Never stop at the pattern.
Doing this out loud
A good interview answer follows a visible pattern:
- Restate the problem and name the quantity you want.
- Say which heuristic you will try first ("these five are i.i.d., so I'll look for a symmetry").
- If stuck, shrink it: "let me do it with two players first".
- Before announcing an answer, test one extreme: probability at or 1, a single item, a degenerate shape.
- Give the answer, with the one-sentence reason it is right.
Interviewers routinely give hints; a candidate who has shown which heuristics they are trying is far easier to help.
Knowledge check
A stick of length 1 is broken at two independent uniform points. What is the expected length of the leftmost piece?
Knowledge check
are i.i.d. continuous. What is ?
Knowledge check
A colleague claims that the expected maximum of i.i.d. uniforms on is . Which observation refutes this fastest?
Key takeaways
- Symmetry: name the transformation that swaps outcomes, then equal outcomes get equal probability.
- uniform points make exchangeable gaps, so the -th smallest has mean .
- Extremes: if the answer should not depend on a parameter, set it to a degenerate value; always test a claimed formula at , or .
- Small cases give conjectures in minutes; follow up with a reason (pairing, induction, an invariant).
- Narrate which heuristic you are trying; it makes you easier to hint and harder to misjudge.
Practice problems
Finished reading?
Answer the 3 knowledge checks to complete this lesson (0 done).