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).
Input: rolls = [3,2,4,3], mean = 4, n = 2
Output: [6,6]
Explanation:
(3+2+4+3+6+6)/6 = 4.
Input: rolls = [1,5,6], mean = 3, n = 4
Output: [2,3,2,2]
Explanation:
(1+5+6+2+3+2+2)/7 = 3.
Input: rolls = [1,2,3,4], mean = 6, n = 4
Output: []
Explanation:
Required missing sum would exceed 6 per die → impossible.
Accepted:
Submission: