223. Flip and Invert

A pixel-art editor stores a black-and-white picture as a grid image in which every cell is either 0 (white) or 1 (black). The editor has a one-click mirror and negative filter that works in two steps on every row: first the row is mirrored, so its cells are read from right to left, and then every cell is inverted, so each 0 becomes 1 and each 1 becomes 0.

Return the picture after the filter has been applied to every row. The rows stay in the same order; only the cells inside each row change. The two steps can be done together in a single pass over each row.

Example 1

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

The first row 1,0,0,0 mirrors to 0,0,0,1 and inverts to 1,1,1,0. The second row 1,1,0,1 mirrors to 1,0,1,1 and inverts to 0,1,0,0.

Example 2

Input:
image = [[1]]
Output:
[[0]]
Explanation:

A single black pixel mirrors to itself and is then inverted to 0.

Example 3

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

0,0 becomes 1,1; 1,1 becomes 0,0; and 0,1 mirrors to 1,0 and inverts to 0,1.

Constraints

1 ≤ image.length, image[0].length ≤ 20
image[i][j] is 0 or 1

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.

Expected complexity

Time
O(m × n)
Space
O(m × n)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…