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 Probability INPUT 1 1 Passenger (Lost Ticket) n = 1 1 seat, 1 passenger ALGORITHM STEPS 1 Base Case Check If n=1, return 1.0 2 Pattern Recognition For n>1: P = 0.5 always 3 Mathematical Proof Recursive probability 4 Return Result O(1) time complexity Formula: if (n == 1) return 1.0 else return 0.5 FINAL RESULT 100% Probability Passenger in own seat! Output: 1.0 [OK] Guaranteed! Key Insight: When n=1, there is only one passenger and one seat. The first passenger MUST sit in seat 1, which is also their assigned seat. Therefore, probability = 1.0 (100% certainty). For n>1, the surprising result is that probability is always exactly 0.5 due to symmetry! TutorialsPoint - Airplane Seat Assignment Probability | Optimal Solution O(1)
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