Rick and Morty play a game where they flip 20 and 21 coins, respectively. What is the probability that Rick gets more heads?
Introduction:
As with most interview problems, we can assume that the numbers 20 and 21 are “arbitrary”. To better understand the question, we can look at some other examples.
Let’s start with the simpler case when the players flip 1 and 2 coins, respectively.
Rick can have either zero or one head, while Morty can have between zero and two, with ‘1’ being the most likely. Given the potential outcomes of the tosses, there are eight possible combinations.
Only one of them has Rick with more heads than Morty, hence a probability of .
If we loosen the inequality and look for the probability that Rick has at least as many heads as Morty, we have a chance of 50%.
Then we add one coin each, getting to 2 and 3 flips:
- we lay out the possible combinations as before;
- count the pairs in which Rick has more heads than Morty;
- and get that there are six out of thirty-two such cases, which gives a probability of .
If we look at the cases where Rick has more or as many heads as Morty, we see that it is again equal to .
With this observation in mind, we can proceed to prove that it holds for any consecutive pair of tosses. Then, we can deduce the probability of strictly more heads.
Solutions:
First Method
To put this into formulae, let:
- , the number of heads Rick has from n tosses,
- , the number of heads Morty has from n+1 tosses.
We know that for n equal to 1 and 2, the probability that is .
We use mathematical induction to prove that given the probability of being at least equals , the same is true and .
When adding one coin to each player, there are four possible scenarios with equal probability: each player either gets one additional head or doesn’t.
Probability of and are both , given our assumption. Since we deal with positive integers, implies .
Let’s think back to what X and Y represent. They count the number of heads in the respective flips. Due to symmetry, we can replace the heads with tails and exchange them in the above probability. If we write the number of tails obtained as the total number of coins for each player minus the number of heads, we get that the probability of being less than or equal to is the same as the probability is less than or equal to .
We replace this last element in the initial equation. Knowing that the probability sets and are complementary, their sum or probabilities is 1, resulting in the final probability being , as we wanted to prove.
Getting back to the initial strict inequality, we only have to find the probability that . We use the same trick, switching heads for tails, but only for X. is , so the probability that is the probability that .
We have 20 coin flips, followed by another 21. represents the number of heads in the 41 tosses. So, there are 41 choose 20 possible options, from a total of .
Thus, we obtain our final answer, , or roughly . To get to this number, you can use Stirling’s approximation:
.
Second Method
The previous solution relies on some neat logic tricks to arrive at the result without much computation. But, if you do not get to this idea quickly, there always is the straightforward, probabilistic approach.
and follow a binomial distribution with and and , respectively.
We can then write the probabilities that X and Y take a particular value k. We look at the random variable , given by . takes values between -20 and 21.
The probability we want to compute is that is less than 0. The probability that Z equals z is the convolution of X and Y:
Replacing with and applying Vandermonde’s identity, we get a simplified formula for . Now we sum over all possible negative values to get the probability that Z is less than 0. Denoting by S the partial sum of combinations and using the symmetry property, we get an alternative formula for S.
Now we use the binomial formula for the sum of combinations and plug both values of S in it. Finally, we get the last value, resulting in having the same probability as the one we obtained from the previous solution.