Reverse Each Binary Row and Invert Its Bits

Quick Overview

Reverse Each Binary Row and Invert Its Bits. Flip the square binary image horizontally by reversing each row, then replace 0 with 1 and 1 with 0.

Reverse Each Binary Row and Invert Its Bits

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Flip the square binary image horizontally by reversing each row, then replace 0 with 1 and 1 with 0. Return the resulting image. ```cpp class Solution { public: vector<vector<int>> flipAndInvertImage(vector<vector<int>>& image); }; ``` ### Examples **Example 1:** ```text image = [[1,0],[0,0]] Output: [[1,0],[1,1]] Explanation: Reverse to[[0,1],[0,0]], then invert. ``` **Example 2:** ```text image = [[1]] Output: [[0]] Explanation: A singleton row stays in place and its bit flips. ``` ### Constraints - Image dimensions are n-by-n with 1 <= n <=20. - Every input entry is 0 or 1. ### Contract considerations Preserve the original binary matrix callable. ```hint Read the boundary condition Which coordinate changes during a horizontal flip? ``` ### Boundary reminders Preserve the original binary matrix callable.

Overview: Reverse Each Binary Row and Invert Its Bits. Flip the square binary image horizontally by reversing each row, then replace 0 with 1 and 1 with 0.

Google logo
Google
Source window: 0–6 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Flip the square binary image horizontally by reversing each row, then replace 0 with 1 and 1 with 0. Return the resulting image.

class Solution {
public:
    vector<vector<int>> flipAndInvertImage(vector<vector<int>>& image);
};

Examples

Example 1:

image = [[1,0],[0,0]]
Output: [[1,0],[1,1]]
Explanation: Reverse to[[0,1],[0,0]], then invert.

Example 2:

image = [[1]]
Output: [[0]]
Explanation: A singleton row stays in place and its bit flips.

Constraints

  • Image dimensions are n-by-n with 1 <= n <=20.
  • Every input entry is 0 or 1.

Contract considerations

Preserve the original binary matrix callable.

Boundary reminders

Preserve the original binary matrix callable.