2028. Find Missing Observations
UnknownView on LeetCode
Time: O(n + m)
Space: O(n)
Problem Overview
Find Missing Observations (Unknown) asks you to solve a structured algorithmic task. This is a common Array / Math pattern in coding interviews. Compute required missing sum; distribute evenly across n dice, adjust remainder.
A full step-by-step explanation is being added. See the study guide for pattern-based practice.
Approach
Compute required missing sum; distribute evenly across n dice, adjust remainder.
Related patterns: Array, Math, Simulation
2028.cs
C#
// Approach: Compute required missing sum; distribute evenly across n dice, adjust remainder.
// Time: O(n + m) Space: O(n)
public class Solution
{
public int[] MissingRolls(int[] rolls, int mean, int n)
{
int targetSum = (rolls.Length + n) * mean;
int missingSum = targetSum - rolls.Sum();
if (missingSum > n * 6 || missingSum < n)
return new int[] { };
int[] ans = new int[n];
Array.Fill(ans, missingSum / n);
missingSum %= n;
for (int i = 0; i < missingSum; ++i)
++ans[i];
return ans;
}
}
Was this solution helpful?
Related Problems
- 4. Median of Two Sorted Arrays(Hard)
- 11. Container With Most Water(Medium)
- 12. Integer to Roman(Medium)
- 13. Roman to Integer(Easy)
- 15. 3Sum(Medium)
- 16. 3Sum Closest(Medium)