1227. Airplane Seat Assignment Probability LeetCode Solution
In this guide, you will get 1227. Airplane Seat Assignment Probability LeetCode Solution with the best time and space complexity. The solution to Airplane Seat Assignment Probability problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Airplane Seat Assignment Probability solution in C++
- Airplane Seat Assignment Probability solution in Java
- Airplane Seat Assignment Probability solution in Python
- Additional Resources

Problem Statement of Airplane Seat Assignment Probability
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.
Example 1:
Input: n = 1
Output: 1.00000
Explanation: The first person can only get the first seat.
Example 2:
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).
Constraints:
1 <= n <= 105
Complexity Analysis
- Time Complexity:
- Space Complexity:
1227. Airplane Seat Assignment Probability LeetCode Solution in C++
class Solution {
public:
double nthPersonGetsNthSeat(int n) {
return n == 1 ? 1 : 0.5;
}
};
/* code provided by PROGIEZ */
1227. Airplane Seat Assignment Probability LeetCode Solution in Java
class Solution {
public double nthPersonGetsNthSeat(int n) {
return n == 1 ? 1 : 0.5;
}
}
// code provided by PROGIEZ
1227. Airplane Seat Assignment Probability LeetCode Solution in Python
class Solution:
def nthPersonGetsNthSeat(self, n: int) -> float:
return 1 if n == 1 else 0.5
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.