Zepruv › Coding problems

Airplane Seat Assignment Probability

Medium · Math, Dynamic Programming, Brainteaser, Probability and Statistics

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:
Return the probability that the nth person gets his own seat.

Example 1

Input: n = 1
Output: 1.00000

The first person can only get the first seat.

Example 2

Input: n = 2
Output: 0.50000

The second person has a probability of 0.5 to get the second seat (when first person gets the first seat).

Constraints

Starter code (python)

class Solution(object):
    def nthPersonGetsNthSeat(self, n):
        """
        :type n: int
        :rtype: float
        """
        

Related problems

Previous: Maximum Length of a Concatenated String with Unique Characters · Next: Tuple with Same Product · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.