KatInterview

Estimating the Probability of a Dice Sum Exceeding a Target

Arrays & HashingAuto-graded · 19 test cases
HardAuto-gradedArrays & Hashingprobabilitycentral-limit-theoremnormal-approximation

Last updated

Apply the central limit theorem and continuity correction to approximate the tail probability of a sum of independent discrete random variables.

You roll a standard fair six-sided die exactly 1,000 times. All rolls are independent. Let S denote the total of all 1,000 face values.

Write a function that estimates the probability that S is strictly greater than a given integer threshold t.

Your solution should:

  • Compute the expected value and variance of S from the distribution of a single roll.
  • Apply a standard normal approximation justified by the central limit theorem.
  • Use a continuity correction to account for the discrete nature of S.
  • Handle edge cases where t falls outside the possible range of S.

Return the estimated probability as a float between 0.0 and 1.0.

Constraints

  • 0 ≤ t ≤ 10,000
  • The number of rolls is fixed at 1,000.
  • Each die shows a value from 1 to 6 with equal probability.
  • You may use standard library functions for the normal distribution or the complementary error function.

Examples

Example 1

Input: estimate_dice_sum_probability(600)

Output: 1

Hints

Hint 1

Start by finding the mean and variance of a single die roll, then scale them to 1,000 independent rolls.

Hint 2

Because S takes only integer values, P(S > t) equals P(S ≥ t + 1). Apply the continuity correction by evaluating the normal CDF at t + 0.5.

Hint 3

Check whether t lies outside the possible range [1000, 6000] before applying the approximation.