← Google Interview Insights

Google·Data Scientist·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Google data scientist technical screen, one meaty probability/algorithms question that took up most of the time. Felt like a math exam more than a coding interview.

Questions Asked (1)

Q1

You have a function rand_bit() that returns 0 or 1 with equal probability, each call independent. How would you use it to generate a random number approximately uniformly distributed on [0, 1)? Walk through a simple algorithm, explain how the approximation error relates to the number of bits used, and analyze the time complexity in terms of rand_bit() calls.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The core idea clicked pretty fast for me: just treat the bits as a binary fraction, so bit 1 is worth 1/2, bit 2 is 1/4, and so on.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by proposing the binary expansion method: generate k bits, interpret them as a binary fraction to get a number in [0,1), and explain that the error is bounded by 2^{-k}. Then analyze the time complexity as O(k) rand_bit() calls, and discuss the trade-off between precision and efficiency.

Pro tip: Mention that you can achieve exact uniformity by using rejection sampling: generate bits until you get a 1, then output the binary fraction formed by the preceding bits. This yields a uniform distribution on [0,1) with expected 2 rand_bit() calls, but the worst-case number of calls is unbounded.

1. Describe the basic algorithm

Generate k independent bits using rand_bit(), concatenate them into a binary fraction (e.g., 0.b1b2...bk), and output the resulting decimal value in [0,1).

2. Explain the approximation error

The output is a multiple of 2^{-k}, so the maximum absolute error from a true uniform continuous distribution is at most 2^{-k}. As k increases, the distribution becomes closer to uniform.

3. Analyze time complexity

The algorithm uses exactly k calls to rand_bit(), so time complexity is O(k). The precision improves exponentially with k, meaning to achieve error ε, you need k = O(log(1/ε)) bits.

4. Discuss trade-offs and alternatives

Mention that fixed k gives a discrete approximation, while rejection sampling can yield exact uniformity but with variable runtime. Compare the trade-offs between simplicity, precision, and efficiency.

Key Points to Mention

  • Binary expansion method: interpreting bits as a binary fraction.
  • Error bound: maximum error is 2^{-k} for k bits.
  • Time complexity: O(k) rand_bit() calls for k bits.
  • Relationship between precision and number of bits: k = O(log(1/ε)) for error ε.
  • Rejection sampling for exact uniformity: expected 2 calls, unbounded worst-case.
  • Trade-off between fixed-bit approximation and exact methods.

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