Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

New 21 Game

XPChallenge Points: 20
levelLevel: Medium

Alice begins at 0 points.
She repeatedly draws points while her score is less than k.
Each draw gives her a random integer from 1 to maxPts (inclusive), with each outcome equally likely.

Once Alice reaches k or more points, she stops drawing.

Your task is to compute the probability that her final score is less than or equal to n.

Your output should be precise within 1e-5 of the correct answer.

Example 1:

Input: n = 5, k = 1, maxPts = 5

Output: 1.00000

Explanation:

Alice draws once and is guaranteed to have at most 5 points. Example 2:

Example 2:

Input: n = 8, k = 2, maxPts = 4

Output: 0.75000

Explanation:

There are 3 favorable score outcomes out of 4 equally likely draws.

Example 3:

Input: n = 25, k = 15, maxPts = 10

Output: 0.72800

Explanation:

The probability depends on all possible reachable sums before exceeding the limit.

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