Class Solution
-
- All Implemented Interfaces:
public final class Solution2028 - Find Missing Observations\.
Medium
You have observations of
n + m6-sided dice rolls with each face numbered from1to6.nof the observations went missing, and you only have the observations ofmrolls. Fortunately, you have also calculated the average value of then + mrolls.You are given an integer array
rollsof lengthmwhererolls[i]is the value of the <code>i<sup>th</sup></code> observation. You are also given the two integersmeanandn.Return an array of length
ncontaining the missing observations such that the average value of then + mrolls is exactlymean. If there are multiple valid answers, return any of them. If no such array exists, return an empty array.The average value of a set of
knumbers is the sum of the numbers divided byk.Note that
meanis an integer, so the sum of then + mrolls should be divisible byn + m.Example 1:
Input: rolls = 3,2,4,3, mean = 4, n = 2
Output: 6,6
Explanation: The mean of all n + m rolls is (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: The mean of all n + m rolls is (1 + 5 + 6 + 2 + 3 + 2 + 2) / 7 = 3.
Example 3:
Input: rolls = 1,2,3,4, mean = 6, n = 4
Output: []
Explanation: It is impossible for the mean to be 6 no matter what the 4 missing rolls are.
Constraints:
m == rolls.length<code>1 <= n, m <= 10<sup>5</sup></code>
1 <= rolls[i], mean <= 6