Airplane Seat Assignment Probability - Problem
The Airplane Seat Assignment Probability Problem

Imagine you're on an airplane with exactly n seats numbered 1 through n, and n passengers are boarding. Here's where it gets interesting:

๐ŸŽซ The first passenger has lost their boarding pass and doesn't know which seat is theirs, so they pick a seat completely at random.

๐Ÿ‘ฅ Each subsequent passenger follows this simple rule:
โ€ข If their assigned seat is available, they sit in it
โ€ข If their assigned seat is occupied, they pick any available seat randomly

๐ŸŽฏ Your mission: Calculate the probability that the last passenger (passenger n) ends up in their own assigned seat.

This is a classic probability puzzle that appears deceptively complex but has an elegant mathematical solution. The key insight lies in understanding that only certain seats matter in determining the final outcome!

Input & Output

example_1.py โ€” Single Passenger
$ Input: n = 1
โ€บ Output: 1.00000
๐Ÿ’ก Note: With only one passenger, they must sit in their own seat (seat 1), so the probability is 1.0
example_2.py โ€” Two Passengers
$ Input: n = 2
โ€บ Output: 0.50000
๐Ÿ’ก Note: First passenger randomly chooses between seat 1 and seat 2. If they choose seat 1, passenger 2 gets seat 2. If they choose seat 2, passenger 2 gets seat 1. Probability = 1/2
example_3.py โ€” Large Case
$ Input: n = 1000
โ€บ Output: 0.50000
๐Ÿ’ก Note: Regardless of the number of passengers, the mathematical principle holds: only seats 1 and n matter, and they are equally likely to be chosen, so the probability remains 1/2

Visualization

Tap to expand
The Airplane Seat Assignment ProbabilityThe Airplane123...n-1nOnly seats 1 and ncan end the game!P1Lost ticketRandom choiceP2Finds seat orpicks randomlyPnGets remainingseatScenario A: Someone sits in seat 1โ†’ Last passenger gets seat nProbability of success = 1Scenario B: Someone sits in seat nโ†’ Last passenger doesn't get seat nProbability of success = 0Final Answer:P = (1 + 0) / 2 = 0.5
Understanding the Visualization
1
Setup
Hotel has n rooms, first guest has no key
2
Chain Reaction
Each displaced guest continues the random selection
3
Two Outcomes
Process ends when someone picks room 1 or room n
4
Equal Probability
By symmetry, both endings are equally likely
Key Takeaway
๐ŸŽฏ Key Insight: The elegant solution emerges from recognizing that this complex-seeming problem reduces to a simple symmetry argument - only two seats matter, and they're equally likely to be chosen!

Time & Space Complexity

Time Complexity
โฑ๏ธ
O(1)

The answer is always 1/2 for n > 1, so no computation needed

n
2n
โœ“ Linear Growth
Space Complexity
O(1)

No additional space required beyond storing the result

n
2n
โœ“ Linear Space

Constraints

  • 1 โ‰ค n โ‰ค 106
  • Output format: Return probability as decimal with exactly 5 decimal places
  • For n = 1, answer is 1.00000; for n > 1, answer is 0.50000
Asked in
Google 23 Amazon 18 Meta 15 Microsoft 12 Apple 8
52.3K Views
Medium Frequency
~15 min Avg. Time
1.8K 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