Probability is the foundation of solving brainteasers involving randomness and uncertainty.
Today, we’ll focus on core principles that will allow you to calculate probabilities and
solve a wide range of problems with confidence. By understanding how probabilities are calculated,
combined, and applied, you'll be equipped to handle many types of interview challenges.
Basic Probability
Probability measures the likelihood of an event occurring. The basic formula is:
Probability = (Number of Favorable Outcomes) / (Number of All Possible Outcomes)
For example, if you roll a standard 6-sided die, the probability of rolling a 3 is:
P(rolling a 3) = 1 / 6
This is because there is 1 favorable outcome (rolling a 3) and 6 possible outcomes in total
(rolling any of the numbers 1 through 6).
Combining Events
In many problems, you'll need to combine probabilities of multiple events. It's crucial to know
when to use P(A and B)
vs P(A or B)
, as they represent very different concepts:
-
P(A and B)
: This is the probability that both events A and B occur
simultaneously. For example, rolling a 4 on the first die and a 5 on the second die are independent
events, so:
P(A and B) = P(A) * P(B)
If P(A) = 1/6
and P(B) = 1/6
, then:
P(A and B) = 1/6 * 1/6 = 1/36
-
P(A or B)
: This is the probability that either event A or event B
occurs, or both. Here, you're exploring all possible ways that one or both events could happen.
For example, if rolling a 4 or a 5 on a single die:
P(A or B) = P(A) + P(B) - P(A and B)
Since it's impossible to roll both a 4 and a 5 on one die, P(A and B) = 0
. Thus:
P(A or B) = 1/6 + 1/6 = 1/3
A common mistake is confusing these two concepts. Use P(A and B)
when you're considering
events that must happen at the same time, and P(A or B)
when you're summing up all possible
ways in which one event or the other could happen.
Law of Total Probability
The Law of Total Probability helps you find the chance of something happening by adding up all the different ways it could happen. For example, imagine you take the bus or the train to work. If it rains, you're more likely to take the bus. If it's sunny, you prefer the train. To find the total chance you take the bus, you look at both cases—rain and sun—and add: (chance of rain × chance of bus if rain) + (chance of sun × chance of bus if sun).
The general formula is:
P(A) = P(A|B₁)·P(B₁) + P(A|B₂)·P(B₂) + ...
Heuristics and Tricks for Solving Probability Problems