java.lang.Object
g1201_1300.s1227_airplane_seat_assignment_probability.Solution

public class Solution extends Object
1227 - Airplane Seat Assignment Probability.<p>Medium</p> <p><code>n</code> passengers board an airplane with exactly <code>n</code> seats. The first passenger has lost the ticket and picks a seat randomly. But after that, the rest of the passengers will:</p> <ul> <li>Take their own seat if it is still available, and</li> <li>Pick other seats randomly when they find their seat occupied</li> </ul> <p>Return <em>the probability that the</em> <code>n<sup>th</sup></code> <em>person gets his own seat</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 1</p> <p><strong>Output:</strong> 1.00000</p> <p><strong>Explanation:</strong> The first person can only get the first seat.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 2</p> <p><strong>Output:</strong> 0.50000</p> <p><strong>Explanation:</strong> The second person has a probability of 0.5 to get the second seat (when first person gets the first seat).</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • nthPersonGetsNthSeat

      public double nthPersonGetsNthSeat(int n)