Skip to content

Practice Flipping an Image

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#832
LeetCode Problem

Flipping an Image

Problem Statement

Given an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image. To flip an image horizontally means that each row of the image is reversed. To invert an image means that each 0 is replaced by 1, and each 1 is replaced by 0.

Source: Flipping an Image on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
image = [[1,1,0],[1,0,1],[0,0,0]]
Output
[[1,0,0],[0,1,0],[1,1,1]]

# Example 2

Input
image = [[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]]

Constraints

n == image.length
n == image[i].length
1 <= n <= 20
images[i][j] is either 0 or 1.

Related LeetCode Problems

Practice more problems similar to Flipping an Image.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.