The Monty Hall Problem Explained
Tech interviewers love to ask questions around conditional probability. I can’t tell why, since it has little to do with actual programming. My guess is that it’s a quick barometer of a candidate’s mathematical background (are they familiar with this type of problem) and preparation (any tech interview prep guide will include examples of this type of problem).
The most popular variation is named after former Let’s Make a Deal host Monty Hall and goes like this:
Imagine you’re a contestant on a game show and given the choice of three doors. Behind one door is a car; behind the other two doors, goats. You pick a door–let’s say No. 1–and the host, who knows what’s behind the doors, opens another door, let’s say No. 3, which has a goat. He then says, “Do you want to change your pick?”
The correct answer, which seems quite counterintuitive, is Yes, you should switch. The odds of the car being behind door No. 3 are 2/3 vs 1/3 for door No. 1.
The reason is that the odds have changed now that we know an additional piece of information. The chance the car is behind door No.1 is still 1/3 but since we can rule out door No. 2, the chance of the car being behind door No. 3 is the combined probability of doors No. 2 and No. 3.
Here’s another way to think about it to drive home the point. Imagine there are 100 doors with 99 goats and 1 car behind them. You pick a door, let’s assume it’s No. 1. The host then opens 98 other doors revealing goats. What are the odds of the car being behind your initial pick, door No. 1, or the remaining unopened door? The answer is you have a 1/100 chance of getting it right with door No. 1 but a 99/100 chance with the remaining door. So you should always switch to the remaining door.
The basic rule of thumb with any conditional probability question is that given new information, you should always change your pick!