Reverse each row horizontally and invert every pixel (0↔1).
You are given an n×n binary matrix `image` where each value is either 0 or 1. To flip an image horizontally, reverse each row. To invert an image, replace each 0 with 1 and each 1 with 0. Your task is to implement `flip_and_invert(image)` that returns the resulting matrix after flipping horizontally and then inverting.
Function signature: `def flip_and_invert(image: list[list[int]]) -> list[list[int]]:`
The input matrix is guaranteed to be square. The function should return a new matrix; modifying the input in place is allowed but not required. Each row must have the same length, and every cell must be 0 or 1.
Constraints
`n` is the number of rows (and columns) with `1 <= n <= 20`.
Each element is either 0 or 1.
Expected time complexity: O(n²).
Example
```python
# Example 1
image = [[1,1,0],[1,0,1],[0,0,0]]
print(flip_and_invert(image))
# Output: [[1,0,0],[0,1,0],[1,1,1]]
# Explanation: First reverse each row:
# [[0,1,1],[1,0,1],[0,0,0]]
# Then invert: [[1,0,0],[0,1,0],[1,1,1]]
# Example 2
image = [[1,0],[0,1]]
print(flip_and_invert(image))
# Output: [[1,0],[0,1]]
# Explanation: Reverse: [[0,1],[1,0]] -> Invert: [[1,0],[0,1]]
```
10 points
~15 min