41. Flipping an Image

EasyArrayArray

Given an n x n binary matrix image, flip the image horizontally (reverse each row), then invert it (replace 0 with 1 and 1 with 0). Return the resulting image.

Input: An n x n binary matrix image.

Output: The image after horizontal flip and inversion.

Examples

Example 1
Input: [[1,1,0],[1,0,1],[0,0,0]]
Output: [[1,0,0],[0,1,0],[1,1,1]]
Explanation: Flip rows: [[0,1,1],[1,0,1],[0,0,0]]. Invert: [[1,0,0],[0,1,0],[1,1,1]].
Example 2
Input: [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]
Output: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
Explanation: Flip then invert each row.
Example 3
Input: [[0]]
Output: [[1]]
Explanation: Flip [0]→[0]. Invert [0]→[1].

Constraints

Asked by

IBMGoogleBloombergMetaAmazonMicrosoft
Solve this problem in the editor →