Can you solve this famous interview question?

Can you solve this famous interview question?

There are 100 passengers lined up (in a random order) to board a plane. The plane is fully booked, meaning there are exactly 100 seats available. Due to a technical malfunction, the first passenger chooses a seat at random, with all seats equally likely. Each of the other passengers then proceeds as follows: if their assigned seat is free, they will sit in it; otherwise, they will take a random available seat. What is the probability that the last passenger will sit in their assigned seat?

This problem, known as the “100-seat airplane problem,” is a popular interview question because it tests candidates’ understanding of probability, recursion, and problem-solving techniques. It frequently appears in tech and finance job interviews, particularly in companies that require strong quantitative skills (e.g., Google, Facebook, Amazon, and finance firms like hedge funds and investment banks).

Can you find the right answer and explain how it’s derived? Before checking the solution, try solving this brain teaser on your own!


Solution

Surprisingly, the solution is exactly 1/2. Let’s break down why.

First, let’s simplify the labeling of the seats. Normally, airplane seats have complex labels like “22A” or “47G,” but here we can just number the seats from 1 to 100, according to which passenger it belongs to. Passenger 1 is assigned to seat 1, passenger 2 to seat 2, and so on.

According to the problem, passenger 1 randomly picks a seat (that could as well be seat 1). Let’s say passenger 1 sits in seat j1 (the superscript refers to the fact that it is passenger 1 who takes this seat). Now, the second passenger in line has two possibilities:

  • (a) If seat 2 is still free (i.e., j1≠2), passenger 2 will sit in seat 2.
  • (b) If j1=2 (meaning passenger 1 took passenger 2’s seat), passenger 2 will be forced to sit in a random seat.

Now, case (a) effectively resets the problem with one fewer passenger and one fewer seat, because passenger 2 is sitting in their own seats and we can forget about them. The first passenger’s random choice has been made, but the same logic applies: each remaining passenger from passenger 3 onward will either sit in their own seat or take a random seat when their seat is already occupied. Therefore, the only thing that case (a) does is to restart the problem with one fewer passenger and we can ignore it.

On the other hand, in case (b), seat 1 and seat 100 are still available, and passenger 2 now has a random choice that includes these two options. Though there are other available seats (seats 3 through 99), they don’t affect the outcome in the way seats 1 and 100 do. Why? Well, if passenger 2 sits somewhere else (let’s say seat 42), then all the other passengers until passenger 42 will be able to sit in their own assigned seats. When passenger 42’s turn comes, the same situation will occur: their seat is taken, but seat 1 and 43 to 100 are still available. Once again, we have reset the problem and are back to case (b) but with fewer passengers left to allocate. Seat 1 and 100, though, will still be available no matter how iterations of case (b) we go through. For this reason, we’ll focus on these two key seats.

From here, the crucial observation is that, regardless of what happens with the intermediate passengers, eventually a passenger will take either seat 1 or seat 100. When this happens, there are two possibilities:

  1. If seat 100 is chosen: The last passenger will have no choice but to sit in seat 1. All the other passengers before them will be able to sit in their own seats.
  2. If seat 1 is chosen: In this case, we have “closed a loop” with passenger 1 and the latest passenger swapping each other’s seats. All the successive passengers will be able to sit in their own assigned seats, and this includes the last passenger (100).

Since these two outcomes are equally likely due to the symmetry of the problem (each passenger has an equal chance of taking any random seat when their seat is occupied), the probability that the last passenger will sit in their assigned seat (seat 100) is exactly 1/2. Moreover, in the other 1/2 of the cases, they will sit in passenger 1’s seat.



要查看或添加评论,请登录

Hari Prathap的更多文章