Dice sum probability
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) → floatExamples
in
[2,6,7]out0.166667What 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.
0:00 of about 30 min
solution.py
InputExpectedGot
[2,6,7]0.166667not run yetsample