KatInterview

Three-Dice Payout: Expected Value by Match Type

Arrays & HashingAuto-graded · 18 test cases
MediumAuto-gradedArrays & Hashingexpected-valueprobabilitycounting

Last updated

Tests ability to count outcome classes for three N-sided dice and combine probability-weighted payoffs into an expected value, including a sign-flip variant.

Three-Dice Payout: Expected Value by Match Type

You toss three independent, fair dice, each with faces numbered 1 through N. Depending on what the three dice show, you collect a reward according to the table below.

OutcomeDescriptionReward
TripleAll three dice show the same face+A dollars
PairExactly two dice show the same face (the third differs)+B dollars
All differentNo two dice share a faceSee below

There are two versions of the game that differ only in the all-different outcome:

  • Version 1 (pays): you receive +C dollars when all three faces differ.
  • Version 2 (costs): you pay C dollars (i.e., collect −C dollars) when all three faces differ.

Compute the expected payoff of a single roll for both versions and return them as a list [version_1, version_2].

How to think about it

Count how many of the N³ equally likely outcomes fall into each class, divide by N³ to get probabilities, then form the probability-weighted average for each version.

Constraints

  • 2 ≤ N ≤ 10,000
  • 0 ≤ A, B, C ≤ 10,000 (amounts are non-negative; the version of the game determines the sign on C)
  • There is no entry fee — the only cash flows are the rewards/costs in the table
  • "Exactly two the same" excludes the triple case
  • Probabilities for the three classes must sum to 1; verify this as a sanity check
  • Round only at the end if rounding is needed; return full floating-point precision

Examples

Example 1

Input: dice_match_expected_payoff(6, 100, 20, 5)

Output: [13.88888888888889, 8.333333333333332]

Example 2

Input: dice_match_expected_payoff(2, 50, 10, 7)

Output: [20, 20]

Example 3

Input: dice_match_expected_payoff(10, 12.5, 4.5, 3.25)

Output: [3.6799999999999997, -0.9999999999999998]

Hints

Hint 1

There are N³ equally likely outcomes in total. How many ways can all three dice land on the same face? How does that fraction simplify?

Hint 2

For the pair case, think about it in two steps: choose which value is repeated (N choices), then choose which of the three dice is the odd one out (3 choices), then choose a different value for that die (N−1 choices).

Hint 3

Once you have the three probabilities, double-check they sum to 1 before computing expected values. The only difference between the two versions is the sign in front of the all-different term.