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

Question

You roll a fair f-sided die (faces 1..f) exactly d times and sum the results. Return the probability, rounded to 6 decimal places, that the sum equals exactly the target. Constraints: 1 <= d <= 30, 2 <= f <= 30, target is any integer. Use a DP over (rolls, partial sum) accumulating counts, then divide by f**d.

Implement
dice_sum_probability(d: int, f: int, target: int) → float
Examples
in[2,6,7]out0.166667
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.