Data Science Interview Prep: Q62
First to Flip Heads: A Biased Coin Probability Puzzle. (Category: Probability)
Players A and B play a turn-based game using a biased coin that lands heads with probability p. Player A flips first, and the two alternate turns until one of them flips heads and wins. Determine the probability that Player A wins the game.
Solution:
Problem Recap.
Two players, A and B, alternate flipping a biased coin.
The coin lands heads with probability p.
Player A flips first.
The game ends as soon as someone flips heads; that player wins.
We want to find P(A), i.e., the probability that player A wins.
Define the Event.
Let P(A) be the probability that player A eventually wins the game.
Analyze the First Flip.
Player A flips first:
With probability p, Player A flips heads immediately and wins. Thus, the probability of immediate win is p.
With probability (1 − p), Player A flips tails and the turn passes to Player B.
Analyze Player B’s Flip after Player A’s Flip.
Player B now flips:
With probability p, Player B flips heads and wins — so Player A loses here.
With probability (1 − p), Player B flips tails and the game returns to the original state: Player A's turn to flip again.
Setup the equation for P(A).
There are two scenarios we consider to evaluate P(A) i.e., the probability that player A wins:
Player A wins on the first flip by tossing heads with probability p.
Player A tosses tails on the first flip with probability (1 − p), then Player B tosses tails on their turn with probability (1 − p), and it becomes Player A’s turn again.
We hope you found the article both enlightening and valuable! For more insightful content delivered straight to your inbox, simply enter your email address below and hit the subscribe button. Stay tuned for future updates!
Reference:
Winning odds in alternating biased coin flips: https://math.stackexchange.com/questions/4236624/general-solution-to-two-players-alternately-flip-a-coin-which-may-be-biased-wh