# Problem Statement
You are given a **0-indexed** 2D integer matrix `grid` of size `n * n` with values in the range `[1, n^2]`. Each integer appears **exactly once** except `a` which appears **twice** and `b` which is **missing**. The task is to find the repeating and missing numbers `a` and `b`.
Return _a **0-indexed** integer array_ `ans` _of size_ `2` _where_ `ans[0]` _equals to_ `a` _and_ `ans[1]` _equals to_ `b`_._
## Constraints
- `2 <= n == grid.length == grid[i].length <= 50`
- `1 <= grid[i][j] <= n * n`
- For all `x` that `1 <= x <= n * n` there is exactly one `x` that is not equal to any of the grid members.
- For all `x` that `1 <= x <= n * n` there is exactly one `x` that is equal to exactly two of the grid members.
- For all `x` that `1 <= x <= n * n` except two of them there is exactly one pair of `i, j` that `0 <= i, j <= n - 1` and `grid[i][j] == x`.
# Solution
First we initialize two [[Python set|sets]], `seen` and `missing`. `seen` will keep track of all the cell values as we iterate through the matrix. Before adding a number though, we check if it already exists in the set. If so, we know that number is the duplicate. `missing` will be initialized as a set containing all the numbers from `1` to `N^2` and as we iterate through the matrix we will remove the cell values. At the end, the one value left is our missing value, so we can return it along with the duplicated value we found.
```python
N = len(grid)
seen = set()
missing = set(range(1, N**2+1))
for i in range(N):
for j in range(N):
cell = grid[i][j]
if cell in seen:
dup = cell
seen.add(cell)
missing.discard(cell)
return [dup, missing.pop()]
```
Time Complexity: O$(n^2)$ | Space Complexity O$(n^2)$