Problem
Two players, A and B, take turns flipping a coin with probability p
of landing heads. Player A flips first, and the first player to get heads wins. What is the probability that Player A wins the game?
This question was asked in a Goldman Sachs Data Scientist interview.
Solution Steps
Step 1: Define Probabilities
Let:
P_A
: Probability that Player A wins.P_B
: Probability that Player B wins.
Since one of the two players must eventually win:
P_B = 1 - P_A
Step 2: Player A's Winning Scenarios
Player A wins in two ways:
Immediate Win: Player A flips heads on the first turn.
Probability =
p
.
Game Continues: Player A flips tails (with probability
1 - p
), and then Player B gets a turn.If the game resets after Player B flips tails, Player A essentially starts again.
From this point, the probability that Player A eventually wins is
P_B = 1 - P_A
.
Combining these cases, the total probability for P_A
is:
P_A = p + (1 - p)(1 - P_A)
Step 3: Solve for P_A
Start with the equation:
P_A = p + (1 - p)(1 - P_A)
Simplify the terms:
P_A = p + (1 - p) - (1 - p)P_A
Combine like terms:
P_A + (1 - p)P_A = p + (1 - p)
Factor out P_A
:
P_A * (1 - p) = 1
Solve for P_A
:
P_A = p / (1 - p)
Final Answer
The probability that Player A wins is:
P_A = p / (1 - p)
Player A has an advantage because they flip first. The recursive nature of the game (flipping tails resets the process) creates a geometric series, leading to the solution.