Simulate Coin Flips to Determine Fairness via Empirical Distribution
GoogleData Scientist · OnsiteLast updated
This question evaluates a candidate's ability to perform simulation-based hypothesis testing by implementing Monte Carlo sampling and computing an empirical two-sided p-value from observed coin-flip counts, emphasizing statistical computation and numerical accuracy.
Scenario
You must test whether a coin is fair by simulation.
Question
Write code that repeatedly simulates n coin flips, records the number of heads, and uses the empirical distribution to compute the two-sided p-value for an observed count of heads without relying on closed-form formulas.
Hints
Focus on efficient Monte Carlo loops or vectorized sampling and correct p-value definition.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.