# 2028. Find Missing Observations

this problem is how to find the edge case

```
[3,5,3]
5
3
```

![](https://4272748102-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LekNH5IywF8mjBxFcnu%2Fuploads%2FbOJR5rm9AFdYmlN29RLU%2Fimage.png?alt=media\&token=282fe219-69d2-49d8-b4be-49c5ba6614be)



```
[6,3,4,3,5,3]
1
6
```

![](https://4272748102-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LekNH5IywF8mjBxFcnu%2Fuploads%2FmyWYgwJ04lGRw8ZwosCX%2Fimage.png?alt=media\&token=fe03bb68-b415-4e63-a7df-e8db4489679f)



![](https://4272748102-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LekNH5IywF8mjBxFcnu%2Fuploads%2FDmlcjOHD1cYQ6oBGFpaq%2Fimage.png?alt=media\&token=72186694-9d03-45a0-9140-53c944755bde)



T: O(m+n)

S: O(n)

```java
class Solution {
    public int[] missingRolls(int[] rolls, int mean, int n) {
        int m = rolls.length;
        int total = 0;
        for (int roll : rolls) {
            total += roll;
        }
        int leftSum = mean*(m+n) - total;
        int leftMean = leftSum/n;
        if (leftMean <= 0 || leftMean > 6) {
            return new int[]{};
        }
        int remainder = leftSum%n;
        if (leftMean == 6 && remainder != 0) {
            return new int[]{};
        }
        int[] res = new int[n];
        Arrays.fill(res, leftMean);
        for (int i = 0; i < remainder; i++) {
            res[i]++;
        }
        return res;
    }
}
```
