Leetcode Problem 2028. Find Missing Observations

2028. Find Missing Observations

Leetcode Solutions

Distribute Missing Sum to Missing Observations

  1. Calculate the current sum of the observed rolls.
  2. Calculate the total sum required for all n + m rolls to achieve the given mean.
  3. Subtract the current sum from the total sum to find the sum of the missing observations.
  4. Check if the sum of the missing observations can be distributed within the range [1, 6] for each observation.
  5. If possible, distribute the sum evenly across the n observations.
  6. If there is a remainder after even distribution, increment some of the observations by 1 until the remainder is exhausted.
  7. Return the array of missing observations if distribution is successful, otherwise return an empty array.
UML Thumbnail

Backtracking to Find Missing Observations

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...