> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Find Missing Observations Python Solution

> Tested Python solution for LeetCode 2028 with 20 pytest cases. Generate a practice environment with lcpy.

LeetCode 2028, [Medium](/catalog/medium). Topics: [Array](/catalog/topics/array), [Math](/catalog/topics/math), [Simulation](/catalog/topics/simulation). [View on LeetCode](https://leetcode.com/problems/find-missing-observations/description/).

Generate this problem as a practice environment: tested reference solution, 20 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 2028   # by problem number
lcpy gen -s find_missing_observations   # by problem name
```

## Problem

You have observations of `n + m` **6-sided** dice rolls with each face numbered from `1` to `6`. `n` of the observations went missing, and you only have the observations of `m` rolls. Fortunately, you have also calculated the **average value** of the `n + m` rolls.

You are given an integer array `rolls` of length `m` where `rolls[i]` is the value of the `i`th observation. You are also given the two integers `mean` and `n`.

Return an array of length `n` containing the missing observations such that the **average value** of the `n + m` rolls is **exactly** `mean`. 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 `k` numbers is the sum of the numbers divided by `k`.

Note that `mean` is an integer, so the sum of the `n + m` rolls should be divisible by `n + m`.

### Examples

```
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.
```

```
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.
```

```
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`
* `1 <= n, m <= 10^5`
* `1 <= rolls[i], mean <= 6`

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_missing_observations/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/find_missing_observations/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(m + n)
    # Space: O(n)
    def missing_rolls(self, rolls: list[int], mean: int, n: int) -> list[int]:
        target = mean * (len(rolls) + n) - sum(rolls)
        if target < n or target > 6 * n:
            return []
        base, extra = divmod(target, n)
        return [base + 1] * extra + [base] * (n - extra)
```

## Complexity

| Time | Space |
| - | - |
| O(m + n) | O(n) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.