You're given an n x n binary matrix representing a black and white image. Your task is to flip the image horizontally, then invert it, and return the resulting image.
What does "flip horizontally" mean?
Each row of the image is reversed. For example, flipping [1,1,0] horizontally results in [0,1,1].
What does "invert" mean?
Each 0 is replaced by 1, and each 1 is replaced by 0. For example, inverting [0,1,1] results in [1,0,0].
Think of this like taking a photo negative and then flipping it like you would flip a pancake!
Input & Output
Visualization
Time & Space Complexity
We traverse the nรn matrix twice: once for flipping and once for inverting
We modify the matrix in-place, using only constant extra space
Constraints
- n == image.length
- n == image[i].length
- 1 โค n โค 20
- image[i][j] is either 0 or 1