Airplane Seat Assignment Probability - Problem
There are n passengers boarding an airplane with exactly n seats. The first passenger has lost their ticket and picks a seat randomly. After that, the rest of the passengers will:
- Take their own seat if it is still available
- Pick other seats randomly when they find their seat occupied
Return the probability that the nth person gets their own seat.
Input & Output
Example 1 — Single Passenger
$
Input:
n = 1
›
Output:
1.0
💡 Note:
With only one passenger, they must sit in their own seat, so probability is 1.0
Example 2 — Two Passengers
$
Input:
n = 2
›
Output:
0.5
💡 Note:
First passenger chooses between 2 seats randomly. 50% chance they pick their own seat (passenger 2 wins), 50% chance they pick passenger 2's seat (passenger 2 loses)
Example 3 — Multiple Passengers
$
Input:
n = 3
›
Output:
0.5
💡 Note:
Mathematical proof shows that regardless of n > 1, the probability is always 0.5. Only the first and last seats matter in determining the outcome
Constraints
- 1 ≤ n ≤ 105
Visualization
Tap to expand
Understanding the Visualization
1
Input
n passengers and n seats on airplane
2
Boarding Process
First passenger sits randomly, others follow rules
3
Output
Probability that last passenger gets correct seat
Key Takeaway
🎯 Key Insight: Only the first and last seats determine the outcome - middle passengers are irrelevant to the final probability
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code