Turning a Biased Coin Into a Fair One With Minimal Flips
Last updated: November 29, 2026
Quick Overview
You have a coin with unknown bias p, such as a flaky network check that passes with some fixed but unknown probability. How do you generate a perfectly fair bit, and what is the expected number of flips?
0
0
0 solved
You have a coin with unknown bias p, such as a flaky network check that passes with some fixed but unknown probability. How do you generate a perfectly fair bit, and what is the expected number of flips?
Randomness extraction comes up in Google SWE phone screens as a mix of probability and algorithm design. Interviewers check the von Neumann trick, the expected cost derivation, and ideas for using flips more efficiently.
What the Interviewer Expects
- Flip in pairs; HT gives 0, TH gives 1, discard HH and TT
- Prove HT and TH have equal probability p(1-p)
- Compute expected flips 1/(p(1-p))
- Note the cost blows up near p = 0 or 1
- Mention extracting more bits from discarded pairs (Peres)
Key Topics to Cover
How to Approach This
- Define your hypotheses (H0 and H1) clearly before performing any test.
- Calculate required sample size BEFORE running an experiment, using power analysis.
- Remember the Central Limit Theorem: sample means become approximately normal with large n.
- Watch for Simpson's paradox. Always segment data by key dimensions.
- Distinguish between statistical significance and practical significance.
Possible Follow-up Questions
- What is the expected number of flips when p = 0.9?
- Can you reuse the discarded HH and TT pairs to extract more bits?
- How would you simulate a coin with bias 1/3 using a fair coin?
- Why do independence and constant p matter?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Browse Statistics QuestionsSample Answer
Clarify
Flips are independent with a constant unknown . We need an output bit that is exactly fair regardless of , and we want its expected cost....
Approach
Use symmetry: the pair HT and the pair TH are equally likely for any . Flip two at a time, output on a mismatch, and retry on a match. The number of pairs until success is geometric....