Code Room
CodingHardcod-g906
Subject Probability dpLevel Senior–Staff~35 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

You start with 0 points and keep drawing while your score is strictly less than k. Each draw adds a uniformly random integer from 1 to maxPts (inclusive) to your score. You stop as soon as your score is >= k. Return the probability that your final score is <= n, rounded to 5 decimal places. 0 <= k <= n <= 10^4, 1 <= maxPts <= 10^4.

Implement
new21_game(n: int, k: int, maxPts: int) → float
Examples
in[10,1,10]out1
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.