0

Can you help me solve this puzzle I received in an online quiz as part of a job application? I only had about 4 minutes to solve it.

There are 2016 passengers about to board a plane, numbered 1 through 2016 in that order. Each passenger is assigned to the seat equal to his or her own number. However, the first passenger disregards instructions and instead of sitting in seat number 1, chooses and sits down in a randomly chosen seat. Each subsequent passenger acts according to the following scheme: if their assigned seat is available, they will sit there; otherwise, they will pick at random from the remaining available seats and sit there. What is the probability that the 1512th passenger ends up sitting in their assigned seat?

A. 1 / 2016

B. 1 / 2

C. 5 / 8

D. 3 / 4

E. None of the above

The idea is to solve the problem using a pen, paper and a calculator. However, I had no idea of the solution during the 4 minutes I was given. I now think the answer is none of the above.

I have written a Monte Carlo simulation in Python (see below) that suggests the answer is >99%. Here is the python code:

import random                                                                
import time

tic = time.time()

N = 2016
n = 1512

def simulate_seat_choosing(N, n):
available_seats = [i for i in range(1, N + 1)]
# First passenger
available_seats.remove(random.choice(available_seats))
# Other passengers
for i in range(2, n):
if i in available_seats:
available_seats.remove(i)
else:
available_seats.remove(random.choice(available_seats))

return available_seats                                                   

num_trials = 10000
num_successes = 0

for i in range(num_trials):
available_seats = simulate_seat_choosing(N, n)
if n in available_seats:
num_successes += 1

print('Fraction of successes = {:.4f}.'.format(num_successes / num_trials))
toc = time.time()
print('\nDone in {:.4f} seconds.'.format(toc-tic))

Here is my terminal output:

Fraction of successes = 0.9975.

Done in 6.3014 seconds.

Peanutlex
  • 1,007
  • 1
    The exact probability, $1 - \dfrac{1}{2016-1512+2}\approx 0.9980237154\dots$, and more generally $1-\dfrac{1}{N-n+2}$ using your naming of variables. Although the linked duplicate primarily focuses on the special case of considering $N=n$ and showing that this results in a probability of $\dfrac{1}{2}$, there are answers focusing on the generalization where we allow $n$ to vary. – JMoravitz Dec 23 '22 at 15:42
  • 1
    To be fair, this is a heck of a question to be asked as an interview question. It seems more an example of shibboleth, seeing if you have previously encountered the problem and know the solution ahead of time. I wouldn't be surprised if the people asking the question had heard the factoid about the special case of $N=n$ and understood it incorrectly and thought it applied to all $n$. The special case is reasonable to expect someone to intuit in a short period of time if they are experienced enough. – JMoravitz Dec 23 '22 at 15:49

0 Answers0