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?

Google
Statistics & Math
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Statistics & Math
Medium

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
von Neumann extractor
geometric distribution
expected value
randomness extraction
independence
How to Approach This
  1. Define your hypotheses (H0 and H1) clearly before performing any test.
  2. Calculate required sample size BEFORE running an experiment, using power analysis.
  3. Remember the Central Limit Theorem: sample means become approximately normal with large n.
  4. Watch for Simpson's paradox. Always segment data by key dimensions.
  5. 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 Questions
Sample Answer
Clarify

Flips are independent with a constant unknown P(H)=p∈(0,1)P(H) = p \in (0, 1). We need an output bit that is exactly fair regardless of pp, and we want its expected cost....

Approach

Use symmetry: the pair HT and the pair TH are equally likely for any pp. Flip two at a time, output on a mismatch, and retry on a match. The number of pairs until success is geometric....


Submit Your Answer
Markdown supported