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.
You must test whether a coin is fair by simulation.
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.
Focus on efficient Monte Carlo loops or vectorized sampling and correct p-value definition.