Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Random Pick with Blacklist

XPChallenge Points: 20
levelLevel: Medium

There are n passengers and n seats on a plane.
The first passenger has lost their seat assignment, so they choose a seat at random.
Each following passenger:

  • Sits in their own seat if it is still available.

  • Otherwise, they randomly choose one of the remaining seats.

You must determine the probability that the nth (last) passenger ends up sitting in their correct seat.

Example 1:

Input: n = 1

Output: 1.0

Explanation:

With only one passenger, they obviously take their own seat.

Example 2:

Input: n = 3

Output: 0.5

Explanation:

The third passenger has a 50% chance to keep their seat.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result