Probability Techniques

The Inclusion-Exclusion Principle

NeetQuant · August 2026 · 4 min read

The systematic way to count a union when the sets overlap.

The formula

For two sets: |A or B| = |A| + |B| - |A and B|.

For three: |A| + |B| + |C| - |AB| - |AC| - |BC| + |ABC|.

In general, alternate: add all singles, subtract all pairs, add all triples, and so on.

Try the complement first

Before reaching for the full machinery, check whether the complement is easier. Questions phrased "at least one" almost always are:

P(at least one) = 1 - P(none)

Probability that at least one of four dice shows a six? Do not enumerate. 1 - (5/6)^4 ≈ 0.518.

That single move handles a large fraction of interview questions that look like inclusion-exclusion problems.

Derangements

The canonical application. A derangement is a permutation with no fixed point - nobody gets their own hat back.

Applying inclusion-exclusion over the events "person k gets their own hat":

D(n)/n! = 1 - 1/1! + 1/2! - 1/3! + ... + (-1)^n / n!

That series is the expansion of e^(-1), so:

P(no one gets their own hat) approaches 1/e ≈ 0.368

This converges startlingly fast - it is already accurate to three decimals at n = 6. Contrast it with the expected number of matches, which is exactly 1 for every n. Both facts about the same problem, and interviewers like asking for them together.

The matching-birthday cousin

Inclusion-exclusion also gives exact answers for problems the birthday problem approximates, though the complement route is far quicker there.

When to stop

The number of terms doubles with each set. With four or more overlapping conditions the formula is technically correct and practically hopeless in an interview. If you find yourself writing the fourth level of terms, there is almost certainly a symmetry or a complement you have missed.

More in combinatorics.

Keep practising

Practise quant interview questions free

Create a free account to attempt hundreds of questions with hints and answer checking, and to run the timed simulators.

Start practising free

Frequently asked questions

What is the inclusion-exclusion principle?
A way to count the size of a union of overlapping sets: add the individual sizes, subtract all pairwise intersections, add all triple intersections, and continue alternating.
What is the probability of a derangement?
For n items it approaches 1/e, about 36.8%, and converges very quickly - it is accurate to three decimal places by n = 6. This is the probability that nobody in a random hat-swap gets their own hat back.