#1227
Medium Algorithms Airplane seat assignment probability
Math Dynamic Programming Brainteaser Probability and Statistics
67.2% acceptance
Feb 25, 2026
658
990
n passengers board an airplane with exactly n seats. The first passenger has lost the ticket and picks a seat randomly. But after that, the rest of the passengers will:
Take their own seat if it is still available, and
Pick other seats randomly when they find their seat occupied
Return the probability that the nth person gets his own seat.
Solution
Rust
Time O(1)
Space O(1)
impl Solution {
pub fn nth_person_gets_nth_seat(n: i32) -> f64 {
if n == 1 { 1.0 } else { 0.5 }
}
}