Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Find Missing Observations

XPChallenge Points: 20
levelLevel: Medium

You’re given rolls (the observed m dice results), an integer mean (the average over all n + m rolls), and the number of missing rolls n. Each die face is 1..6.
Return any length-n array of missing rolls such that the overall average is exactly mean. If impossible, return [].

Key idea:
Let total = mean * (n + m) be the required sum of all rolls.
Then missing = total - sum(rolls) must satisfy n ≤ missing ≤ 6n.
If feasible, distribute missing across n slots with values in [1,6] (e.g., an even spread).

Example 1:

Input: rolls = [3,2,4,3], mean = 4, n = 2

Output: [6,6]

Explanation:

(3+2+4+3+6+6)/6 = 4.

Example 2:

Input: rolls = [1,5,6], mean = 3, n = 4

Output: [2,3,2,2]

Explanation:

(1+5+6+2+3+2+2)/7 = 3.

Example 3:

Input: rolls = [1,2,3,4], mean = 6, n = 4

Output: []

Explanation:

Required missing sum would exceed 6 per die → impossible.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result