Problem
Ask
Submissions

Problem: Flipping an Image

Medium
30 min
Explore how to flip an image horizontally and invert its pixels using bitwise techniques in Python. Understand the approach to manipulate square matrix images of 0s and 1s, and practice implementing efficient solutions to this common coding interview problem.

Statement

Given that an image is represented by an (n×n)(n \times n) matrix containing 00s and 11s, flip and invert the image, and return the resultant image.

Horizontally flipping an image means that the mirror image of the matrix should be returned. Flipping [1,0,0][1, 0, 0] horizontally results in [0,0,1][0, 0, 1].

Inverting an image means that every 00 is replaced by 11, and every 11 is replaced by 00. Inverting [0,1,1][0, 1, 1] results in [1,0,0][1, 0, 0].

Constraints:

  • Image should be a square matrix.
  • 1n201 \leq n \leq 20
  • images[i][j] is either 00 or 11.
Problem
Ask
Submissions

Problem: Flipping an Image

Medium
30 min
Explore how to flip an image horizontally and invert its pixels using bitwise techniques in Python. Understand the approach to manipulate square matrix images of 0s and 1s, and practice implementing efficient solutions to this common coding interview problem.

Statement

Given that an image is represented by an (n×n)(n \times n) matrix containing 00s and 11s, flip and invert the image, and return the resultant image.

Horizontally flipping an image means that the mirror image of the matrix should be returned. Flipping [1,0,0][1, 0, 0] horizontally results in [0,0,1][0, 0, 1].

Inverting an image means that every 00 is replaced by 11, and every 11 is replaced by 00. Inverting [0,1,1][0, 1, 1] results in [1,0,0][1, 0, 0].

Constraints:

  • Image should be a square matrix.
  • 1n201 \leq n \leq 20
  • images[i][j] is either 00 or 11.