Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    1227 - Airplane Seat Assignment Probability\.

    Medium

    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 <code>n<sup>th</sup></code> 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:

    • <code>1 <= n <= 10<sup>5</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Double nthPersonGetsNthSeat(Integer n)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait