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
Airplane Seat Assignment: From Chaos to Order123455 seats availableP1P2P3P4P5Lost ticket!Wants seat 5sits randomlyBoarding Rules:1. Sit in own seat if available2. Sit randomly if own seat taken3. P1 always sits randomlyAnswer: 0.5for n > 1What is the probability that P5 gets seat 5?🎯 Mathematical insight: Only seats 1 and 5 matter!
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
Asked in
Google 15 Microsoft 12 Amazon 8 Facebook 6
28.0K Views
Medium Frequency
~15 min Avg. Time
850 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen