ML Interview Q Series: Conditional Probability for Restoring a Message with Repeated Letters
Browse all the Probability Interview Questions here.
A drunkard removes two randomly chosen letters of the message HAPPY HOUR (which has 9 letters: H, A, P, P, Y, H, O, U, R). His drunk friend then puts those two letters back in a random order. What is the probability that HAPPY HOUR appears again?
Short Compact solution
We let B1 be the event that the two removed letters are both H, B2 be the event that the two removed letters are both P, and B3 be the event that two distinct letters are removed. Then the probability that HAPPY HOUR appears again is computed by conditioning on these events:
Comprehensive Explanation
First, note that the message HAPPY HOUR contains 9 letters in total. Among these 9 letters, there are 2 H's and 2 P's, while the remaining letters (A, Y, O, U, R) appear once each. The total number of ways to choose 2 letters out of 9 is (9 choose 2) = 36.
To see why we partition the probability space into three main events:
B1: Both removed letters are the two H's. B2: Both removed letters are the two P's. B3: The two removed letters are distinct (meaning either they are not the same letter, or they do not come from the pairs of identical letters).
Each event's probability is computed based on the total of 36 ways to remove letters:
Probability of B1 (the two removed letters are the two H's) = 1/36, because out of the 36 ways to pick 2 letters, there is only 1 way to pick both H's.
Probability of B2 (the two removed letters are the two P's) = 1/36 for the same reasoning.
Probability of B3 (two distinct letters are removed) = 1 - 1/36 - 1/36 = 34/36.
Next, for each event B1, B2, or B3, we compute the conditional probability that the final arrangement is still HAPPY HOUR once the letters are placed back:
P(A | B1) = 1. If the two letters removed are the identical H's, any order of returning those H's results in the same arrangement as the original, so it is certain (probability 1) that we get the original message.
P(A | B2) = 1 for the same reason, except now it is for the identical P's.
P(A | B3) = 1/2. Here, two distinct letters are removed. When these two distinct letters are put back randomly, there are exactly 2 ways to order them, and only 1 of these ways yields the original arrangement. Hence the probability is 1/2.
Putting it all together:
The contribution to P(A) from B1 is 1 * (1/36).
The contribution to P(A) from B2 is 1 * (1/36).
The contribution from B3 is (1/2)*(34/36).
Summing these contributions leads to:
2/36 + (1/2)*(34/36) = 2/36 + 17/36 = 19/36.
Hence, the probability that the message HAPPY HOUR reappears exactly in its original form is 19/36.
Potential Follow-up Question #1
Why do we assume that P(A | B3) = 1/2 specifically?
When two distinct letters are removed, they can be placed back in any of 2 possible orders. Since exactly one of those orders is the correct one that restores the original message, the chance is 1 out of 2. This assumes that each ordering is equally likely.
Potential Follow-up Question #2
Could identical letters other than H or P influence the probability calculation?
In HAPPY HOUR, only H and P are repeated letters. No other letters repeat. If there had been more repeated letters (say multiple 'R's or multiple 'A's), the logic would extend similarly: events where a pair of identical letters are removed would give a conditional probability of 1 for restoring the word, since the random reordering of identical letters does not matter. The final answer would then need to factor in those new probabilities accordingly.
Potential Follow-up Question #3
What if the two letters chosen include one repeated letter and one unique letter? Is that part of event B3?
Yes, any combination that involves two different letters, including one that might come from a repeated set (e.g., removing one H and one P, or one H and Y, or one P and R, etc.), still counts as removing two distinct letters overall. Such scenarios are handled uniformly in event B3 because the friend must guess the correct order for those two distinct letters, with probability 1/2.
Potential Follow-up Question #4
How would we handle a scenario where the friend places the letters back randomly in any of 9 positions?
In that different scenario, the entire sampling space changes. The problem as stated assumes the friend places the removed letters back into the same two positions. If we changed the problem so that the friend can place letters in any positions, we would need a more elaborate approach that considers permutations of all letters. This would significantly affect the probabilities. But for the question asked, we are specifically told the two letters go back exactly where they came from, just in a random order relative to each other.
Below are additional follow-up questions
Potential Follow-up Question #5
What if the friend tends to put back letters with different probabilities for each order, rather than assigning equal probability to the two permutations?
Answer The standard solution assumes that each of the two possible ways to reorder a pair of letters (when they are distinct) is equally likely. In a real-world scenario, it is possible the drunk friend might systematically prefer one ordering over the other. Suppose the probability of placing them in the correct order is p, and the probability of placing them in the incorrect order is (1 - p). Then:
When identical letters (like two H’s) are removed, it does not matter how they are reordered, so the probability of restoring the message is always 1.
When two distinct letters are removed, the probability of restoring the message is p (instead of 1/2).
With this adjustment, you would recalculate the probability by weighting each of these scenarios with the new conditional probabilities. If p differs significantly from 1/2, the final probability of restoring the message will deviate from 19/36 accordingly. This emphasizes how sensitive the result can be to assumptions about uniform placement—small biases in the friend’s reordering behavior can change the final probability.
Potential Follow-up Question #6
What if each letter is not equally likely to be removed? For instance, suppose the drunkard has a tendency to remove bigger letters (like H or P) more often.
Answer The standard result of 19/36 rests on the assumption that every pair of positions in the word is equally likely to be chosen. If certain letters are favored for removal, the probabilities of events B1, B2, and B3 change. For example, if H’s and P’s are more frequently chosen than the single letters, then:
The probability that both removed letters are H (event B1) could be higher than 1/36, because those letters are more likely to be picked.
Similarly, the probability that both removed letters are P (event B2) might also deviate from 1/36.
The probability of removing two distinct letters (event B3) would be adjusted accordingly.
You would need to know or estimate the distribution of removal probabilities for each letter, recalculate the probabilities of B1, B2, and B3 under that new distribution, and then combine these with the conditional probabilities P(A | B1), P(A | B2), and P(A | B3) as before. In practice, such non-uniform selection would require either direct observation of the drunkard’s tendencies or an assumption model, making the problem more complex.
Potential Follow-up Question #7
Does the position in which the letters are removed matter if the friend also randomly shuffles all positions (not just the two removed letters)?
Answer Yes, it fundamentally changes the problem. The stated approach assumes the friend is only randomly reordering the two removed letters before placing them back in their original positions. If, instead, the friend can shuffle letters among any positions in the phrase—effectively rearranging all nine letters—then the outcome space is larger and the probability calculations must consider permutations of all nine letters.
In such a scenario, you would need to calculate the probability that, after a random permutation of all nine letters, the arrangement is still HAPPY HOUR. The probability of returning to the exact original order by a uniformly random permutation of 9 letters is 1/9!, which is vastly different from 19/36. So the assumption that only the two removed letters are swapped (in a 2-letter micro-permutation) is critical to the result in the original solution.
Potential Follow-up Question #8
What are potential issues if the friend accidentally mixes up the removed letters with other letters lying around, or if there are multiple copies of the same letter accessible?
Answer The core assumption is that the friend only reintroduces the same two removed letters back into the message. If the friend has access to a random pile of letters that includes duplicates from other signs, we can no longer guarantee that the same letters get returned. This leads to a more complicated situation:
The friend might unknowingly pick up a different letter that is identical, thus effectively returning the correct letter but from a different source—this would not necessarily break the solution if the letter is the same character.
The friend might pick up a different letter altogether, altering the composition of the word and making restoration impossible (or extremely unlikely).
If multiple copies of a letter are available, then even returning “the same letter” might not preserve the original exact letter but preserve the character identity—under certain definitions, that might still recreate HAPPY HOUR visually, but if we track physical letters as unique objects, it wouldn’t be the same.
In any of these cases, you can see the real-world complexity: the probability of a perfect restoration depends on whether the exact same physical letters must return or simply the same letter characters. Each assumption change can force a recalculation of the probabilities.
Potential Follow-up Question #9
Does it matter if the billboard contains more letters beyond HAPPY HOUR, and the drunkard could remove letters from anywhere on the billboard?
Answer Yes, it changes both the sample space and the event definitions. If the billboard has additional text, then the probability of removing letters from the specific section that spells HAPPY HOUR is affected by how likely the drunkard is to remove letters from that entire set of letters. For instance:
The total number of letters from which the two letters are chosen would be larger.
The probability that exactly two letters from the HAPPY HOUR portion get removed is now smaller.
There could be repeated letters both in HAPPY HOUR and in the broader text that further complicates which “H” or “P” is removed.
Thus, to maintain the 19/36 figure, you must isolate the scenario so that removal is only from the 9 letters forming HAPPY HOUR. Adding more letters broadens the scope, and you would have to carefully recast the events B1, B2, B3, or expand them to B1’, B2’, B3’, etc., to reflect the new set of possible removals.
Potential Follow-up Question #10
How would we verify this result empirically using a simulation, and what caveats might arise in a real-world implementation?
Answer You can empirically verify the 19/36 probability by simulating many trials of the process:
Represent the string “H A P P Y H O U R” in a data structure (such as a list).
Repeatedly simulate removing two letters at random.
Randomly reorder those two letters, then place them back in their original positions.
Check whether the resulting arrangement is still HAPPY HOUR.
By running a large number of simulations, the fraction of trials that end with HAPPY HOUR should converge to around 19/36 (~0.5277). However, some real-world deviations may occur:
Inconsistent random number generation or biases in how letters are physically picked up.
Human errors in physically returning the letters to the exact spots.
The possibility of misreading or mislabeling letters, particularly if the typeface or shape is confusing (like certain stylized letters).
These real-world issues can skew the distribution of outcomes away from the idealized 19/36. Nonetheless, in a purely computational context with uniform random choices, an experiment should reliably confirm the theoretical probability.