FastPrepNew 21 Game Probability
Problems/New 21 Game Probability

New 21 Game Probability

UiPath logoUiPath● HardFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report establishes the exercise identity and central capability. This practice contract supplies only the smallest portable interface, deterministic boundary rules, and output representation needed for consistent execution.

A player starts with 0 points and repeatedly draws an integer uniformly at random from 1 through maxPts, inclusive. The player stops drawing as soon as the score is at least k.

Return the probability that the final score is at most n.

Function

new21Game(n: int, k: int, maxPts: int) → double

Examples

Example 1

n = 10k = 1maxPts = 10return = 1.0

Every possible first draw is at most 10.

Example 2

n = 6k = 1maxPts = 10return = 0.6

Exactly six of the ten equally likely first draws finish at 6 or below.

Example 3

n = 21k = 17maxPts = 10return = 0.7327777870686082

Dynamic programming accumulates the probability of every reachable stopping score from 17 through 21.

Constraints

  • 0 <= k <= n <= 10000
  • 1 <= maxPts <= 10000
  • The result is accepted with absolute tolerance 1e-9.

More UiPath problems

  • Bus RoutesPHONE SCREEN · Seen Nov 2026
  • Swim in Rising WaterPHONE SCREEN · Seen Nov 2026
  • Excel Sheet Column TitlePHONE SCREEN · Seen May 2026
See UiPath hiring insights
Saved
class Solution {
    public double new21Game(int n, int k, int maxPts) {
      // write your code here
    }
}
Checking account…