[
math
random
dp
brainteaser
]
Leetcode 1227. Airplane Seat Assignment Probability
Problem statement
https://leetcode.com/problems/airplane-seat-assignment-probability/
Solution
It is classical probability theory problem, answer is 0.5
for n > 1
and 1
if n = 1
. It can be showed that we have recursion f(n) = 1 / n + (n - 2) / n * f(n - 1)
and then solve it.
Complexity
It is O(1)
for time and space.
Code
class Solution:
def nthPersonGetsNthSeat(self, n):
return 0.5 if n > 1 else 1