Flip and Invert Image

MATRIX

Problem

Given an n x n binary matrix image, flip the image horizontally and then invert it.

To flip the image horizontally, reverse each row.

To invert the image, change each 0 to 1 and each 1 to 0.

Return the transformed image.

Examples

flipImage([[1,1,0],[1,0,1],[0,0,0]]) // [[1,0,0],[0,1,0],[1,1,1]] /* Why? - Flip each row: * [1,1,0] -> [0,1,1] * [1,0,1] -> [1,0,1] * [0,0,0] -> [0,0,0] - Invert the image: * [0,1,1] -> [1,0,0] * [1,0,1] -> [0,1,0] * [0,0,0] -> [1,1,1] So, the final modified image is: [[1,0,0],[0,1,0],[1,1,1]] */ flipImage([[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]) // [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]] /* Why? - Flip each row: * [1,1,0,0] -> [0,0,1,1] * [1,0,0,1] -> [1,0,0,1] * [0,1,1,1] -> [1,1,1,0] * [1,0,1,0] -> [0,1,0,1] - Invert the image: * [0,0,1,1] -> [1,1,0,0] * [1,0,0,1] -> [0,1,1,0] * [1,1,1,0] -> [0,0,0,1] * [0,1,0,1] -> [1,0,1,0] So, the final modified image is: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]] */
Loading...
1
1
0
1
0
1
0
0
0