Ctrl K

Mirror and Negate a Bitmap

Easy
A black-and-white picture is given as an n × n matrix bitmap of zeros and ones. Apply two operations and return the result: 1. mirror the picture horizontally, so each row is reversed; 2. negate it, so every 0 becomes 1 and every 1 becomes 0.
Example 1
bitmap=[[1, 0, 0], [0, 1, 1], [1, 1, 1]] → [[1, 1, 0], [0, 0, 1], [0, 0, 0]]

Mirrored rows: [0,0,1], [1,1,0], [1,1,1]. After negating: [1,1,0], [0,0,1], [0,0,0].

Example 2
bitmap=[[0, 1], [0, 0]] → [[0, 1], [1, 1]]

[0,1] → [1,0] → [0,1]; [0,0] → [0,0] → [1,1].

Example 3
bitmap=[[1]] → [[0]]
Constraints
  • 1 ≤ n ≤ 20
  • len(bitmap) == len(bitmap[i]) == n
  • bitmap[i][j] is 0 or 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsMatch-Three Cascade MediumRepack the Tray EasySwap Rows and Columns EasyPawns the Rook Can Take EasyRolling Grid Easy
loading Python…
Input
bitmap=[[1, 0, 0], [0, 1, 1], [1, 1, 1]]
Expected
[[1, 1, 0], [0, 0, 1], [0, 0, 0]]

Run checks the first 3 tests in your browser. Submit checks all 56 tests on the server, hidden ones included.