← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Google data analyst interview with a probability/statistics problem about simulating a fair coin using a biased one. Pretty short content to go on but the question itself is a classic.

Questions Asked (1)

Q1

You have a biased coin with an unknown probability of heads. How would you use it to simulate a fair 50/50 coin flip?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is the Von Neumann trick and I blanked on the name but remembered the logic: flip twice, if you get HT treat it as heads, TH as tails, and discard HH or TT.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Explain the von Neumann extractor: flip the coin twice, and if the results are different (HT or TH), output the first result; if the same (HH or TT), discard and repeat. This yields a fair 50/50 outcome regardless of the coin's bias, as long as the bias is not 0 or 1.

Pro tip: Mention the expected number of flips (1/(2p(1-p))) and note that while the method is unbiased, it may be inefficient for extreme biases; you can also discuss alternative approaches like using multiple flips to generate a random bit with fewer expected flips.

1. Understand the problem

Recognize that the coin is biased with unknown probability p of heads, and we need a fair 50/50 outcome. The solution must not depend on knowing p.

2. Pair flips to create symmetry

Flip the coin twice. The sequences HT and TH are equally likely (both have probability p(1-p)), while HH and TT are not equally likely unless p=0.5.

3. Define the output rule

If the pair is HT, output Heads; if TH, output Tails. If HH or TT, discard the pair and repeat the process.

4. Prove fairness

Since HT and TH are equally likely, the conditional probability of outputting Heads given a non-discarded pair is 1/2. Thus the final output is fair.

5. Analyze efficiency and edge cases

The expected number of flips is 1/(2p(1-p)), which is minimized at p=0.5 (2 flips) and grows as p approaches 0 or 1. If p=0 or 1, the method never terminates; in practice, assume 0<p<1.

Key Points to Mention

  • Von Neumann's algorithm for generating unbiased random bits from a biased source.
  • The symmetry of the sequences HT and TH: both have probability p(1-p).
  • Discarding HH and TT ensures independence from the bias.
  • Expected number of flips: 1/(2p(1-p)), which is at least 2.
  • The method works for any p in (0,1), but fails if p=0 or p=1.
  • Potential optimizations for extreme biases, such as using more flips per trial or other extractors.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.