Medium · Python / C++ Quant Coding · Coding · ~15 min · #43
Exact Dice-Sum Probabilities
Implement dice_sum_prob(n: int, target: int) -> float returning the exact probability that the sum of fair six-sided dice equals target.
Avoid enumerating all outcomes.
Examples
Input: dice_sum_prob(2, 7)
Output: 0.16666666666666666
Input: dice_sum_prob(3, 10)
Output: 0.125
Constraints
- •
1 ≤ n ≤ 50
- •
Return 0.0 for impossible targets.
Hints · 0 of 2 shown
Worked solution
Give the problem an honest attempt first, then reveal the full explanation.
Related questions
Concepts
Dynamic programmingConvolution of distributions
Relevant for
Quant DeveloperQuant ResearcherQuant Trader