← Google Interview Insights

Google·Data Scientist·Technical Phone Screen·Senior

Senior
Jul 2026

Summary

Google data scientist technical screen, one coding question focused on Monte Carlo simulation for hypothesis testing. Pretty niche for a DS role but made sense given the team.

Questions Asked (1)

Q1

Write code that simulates n coin flips many times, tracks the head counts across simulations, and uses that empirical distribution to compute a two-sided p-value for an observed number of heads. No closed-form stats formulas allowed.

A/B Testing & ExperimentationAlgorithms & Data Structures
Author's notes

My first instinct was to reach for scipy.stats and they immediately said no.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Write a simulation function that flips n fair coins many times (e.g., 100,000 iterations) and records the number of heads per simulation. Then compute the two-sided empirical p-value as the proportion of simulated head counts whose absolute deviation from the expected value (n/2) is at least as extreme as the observed deviation. Avoid any closed-form probability formulas; rely solely on the simulated distribution.

Pro tip: Mention that you would set a random seed for reproducibility and discuss the trade-off between number of simulations and Monte Carlo error, showing awareness of practical implementation concerns.

1. Define simulation parameters

Specify n (number of flips per simulation), number of simulations (e.g., 100,000), and the observed number of heads. Use a fixed random seed for reproducibility.

2. Simulate coin flips and record head counts

For each simulation, generate n independent Bernoulli trials (e.g., using random.random() < 0.5) and count the number of heads. Store these counts in an array.

3. Compute the empirical two-sided p-value

Calculate the absolute deviation of the observed count from the expected value (n/2). Then compute the proportion of simulated counts whose absolute deviation is greater than or equal to the observed deviation.

4. Validate and interpret results

Check that the simulated distribution is centered around n/2 and that the p-value is between 0 and 1. Discuss how increasing the number of simulations reduces Monte Carlo error.

Key Points to Mention

  • Use of Monte Carlo simulation to approximate the null distribution without closed-form formulas
  • Two-sided p-value definition: proportion of simulated outcomes at least as extreme as observed, based on absolute deviation from the mean
  • Importance of setting a random seed for reproducibility
  • Trade-off between number of simulations and computational cost / accuracy
  • Handling edge cases (e.g., observed count exactly at the mean, very large n)
  • Potential use of vectorized operations (e.g., NumPy) for efficiency

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