1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
LeetCode/cs/find-missing-observations.cs
Matej Focko add853b5e4
cs: add «2028. Find Missing Observations»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-09-05 10:52:04 +02:00

22 lines
552 B
C#

public class Solution {
public int[] MissingRolls(int[] rolls, int mean, int n) {
var sum = rolls.Sum();
var remainder = (rolls.Length + n) * mean - sum;
if (remainder < n || remainder > 6 * n) {
// cannot construct such rolls
return [];
}
var (roll, unmatched) = (remainder / n, remainder % n);
var missing = new int[n];
Array.Fill(missing, roll);
for (int i = 0; i < unmatched; ++i) {
++missing[i];
}
return missing;
}
}