New 21 Game Probability
Reported by candidates from UiPath's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt at this UiPath OA question, reported in September 2026, is writing the obvious DP and watching it time out. New 21 Game Probability looks like a simple dice game, but the naive version recomputes a sum of up to maxPts terms for every score, and with values up to 10000 that gets ugly fast. The real pattern is dynamic programming with a sliding window sum. If you've got the invite and the clock is ticking, know this one cold. StealthCoder is the safety net if your mind goes blank mid-assessment.
The problem
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 = 10 k = 1 maxPts = 10 return = 1.0 Every possible first draw is at most 10. Example 2 n = 6 k = 1 maxPts = 10 return = 0.6 Exactly six of the ten equally likely first draws finish at 6 or below. Example 3 n = 21 k = 17 maxPts = 10 return = 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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Define dp[i] as the probability of ever reaching score i. dp[0] = 1. For any i, dp[i] is the sum of dp[j] over the previous maxPts scores j that were still drawing (j < k), divided by maxPts. Don't recompute that sum. Keep a running window sum: add dp[i] to it when i < k, and subtract dp[i - maxPts] when it falls out of range. The answer is the sum of dp[i] for i from k to n. The classic pitfall is including scores at or above k in the window, since the player has stopped there and can't draw again. Also handle k = 0 up front, where the player never draws and the answer is 1.0. Doubles are fine given the 1e-9 tolerance. If the window logic slips under pressure, StealthCoder can hand you the clean version during the live OA.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill New 21 Game Probability cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass UiPath's OA.
UiPath reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
New 21 Game Probability FAQ
What's the trick to New 21 Game Probability?+
Use a DP over scores with a sliding window sum. dp[i] equals the window total divided by maxPts. The window only includes scores below k, because drawing stops at k or more. This turns an O(n * maxPts) solution into O(n).
Why does my first solution time out?+
You're probably summing maxPts previous entries for every score. With n and maxPts both near 10000, that's around 100 million operations or more. Maintain a running sum, add the new term and subtract the one leaving the window, so each step is constant time.
What edge cases should I test?+
Test k = 0, which should return 1.0 since no drawing happens. Test n >= k + maxPts - 1, where the answer is also 1.0 because no final score can exceed n. Test k = 1 with small n, like the 0.6 example. These catch most off-by-one mistakes.
Is this a simulation problem?+
Not in practice. It's tagged as a simulation in some places, but Monte Carlo won't hit the 1e-9 tolerance. You need an exact probability DP. Treat it as dynamic programming with prefix or window sums.
How do I prepare for this in 48 hours?+
Write the DP once from scratch, then rewrite it with the sliding window. Run the three given examples and check that 21, 17, 10 gives about 0.73278. Then do two or three similar probability DP problems so the recurrence feels automatic before the OA.