1227. Airplane Seat Assignment Probability
Input: n = 1
Output: 1.00000
Explanation: The first person can only get the first seat.Input: n = 2
Output: 0.50000
Explanation: The second person has a probability of 0.5 to get the second seat (when first person gets the first seat).// Recursion
double nthPersonGetsNthSeat(int n) {
if (n == 1) return 1.0;
return 1.0 / n + static_cast<double>(n - 2) / static_cast<double>(n) * nthPersonGetsNthSeat(n - 1);
}Last updated