← LinkedIn Interview Insights

LinkedIn·Machine Learning Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
May 2026

Summary

LinkedIn MLE interview with a probability/randomness question that sounds like a classic puzzle but has a lot of depth once you get into the weeds of efficiency.

Questions Asked (1)

Q1

You have a biased coin function that returns 0 with unknown probability p and 1 with probability (1-p). Implement a function that returns a uniformly random integer from 0 to 6 inclusive. Walk through your approach, analyze the expected number of calls to the biased function, and discuss how you'd minimize it.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The von Neumann trick clicked for me pretty fast: call the biased function twice, if you get (0,1) output 0, if (1,0) output 1, otherwise discard and retry.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use the von Neumann extractor to generate fair bits from pairs of biased coin flips, then combine bits to produce a uniform integer from 0 to 6. Analyze the expected number of calls and optimize by using rejection sampling with a larger bit budget to reduce waste.

Pro tip: Mention that the expected number of calls can be reduced by generating multiple fair bits per pair and using rejection sampling with a buffer, but note the trade-off between complexity and efficiency.

1. Generate fair bits

Explain how to use the biased coin to generate fair bits by flipping twice: if outcomes are (0,1) output 0, if (1,0) output 1, otherwise discard and repeat.

2. Combine bits to form integers

Use the fair bits to generate a uniform integer in a range. Since 7 is not a power of 2, use rejection sampling: generate 3 fair bits to get a number 0-7, reject 7, and return the result.

3. Analyze expected calls

Calculate the expected number of biased coin flips: each fair bit requires 1/(2p(1-p)) pairs on average, and each integer requires 8/7 fair bits on average, so total expected flips = (8/7) * (1/(p(1-p))).

4. Optimize efficiency

Discuss how to minimize calls by generating multiple fair bits at once and using a buffer to reduce rejection waste, or by using a more efficient extraction method like Elias's algorithm.

5. Handle edge cases

Consider cases where p=0 or p=1 (coin always returns same value), and discuss fallback or error handling.

Key Points to Mention

  • Von Neumann extractor for generating fair bits from biased coin flips.
  • Rejection sampling to map fair bits to uniform integers in a non-power-of-2 range.
  • Expected number of calls formula: (8/7) * (1/(p(1-p))) for the basic method.
  • Optimization techniques: generating multiple fair bits per pair, using a buffer, or advanced extractors like Elias's.
  • Trade-offs between simplicity and efficiency in implementation.
  • Edge cases: p=0 or p=1, and how to handle them.

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