Tap here to switch tabs
Problem
Submissions

Problem: Minimum Flips to Make Binary Grid Palindromic II

Minimum Flips to Make Binary Grid Palindromic II asks you to flip the fewest binary grid cells so every row and column reads the same backward, with the total ones divisible by four.

Statement

You are given an m×nm \times n binary matrix grid.

A row is considered palindromic if it reads the same from left to right as it does from right to left. Similarly, a column is considered palindromic if it reads the same from top to bottom as it does from bottom to top.

A matrix is considered palindromic if every row is palindromic, every column is palindromic, and the total number of 11’s in the matrix is divisible by 44.

In one operation, you can flip any element in grid from 00 to 11 or from 11 to 00.

Return the minimum number of flips required to make grid palindromic.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 1≤m×n≤2×1051 \leq m \times n \leq 2 \times 10^5

  • 0≤0 \leq grid[i][j] ≤1\leq 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Flips to Make Binary Grid Palindromic II

Minimum Flips to Make Binary Grid Palindromic II asks you to flip the fewest binary grid cells so every row and column reads the same backward, with the total ones divisible by four.

Statement

You are given an m×nm \times n binary matrix grid.

A row is considered palindromic if it reads the same from left to right as it does from right to left. Similarly, a column is considered palindromic if it reads the same from top to bottom as it does from bottom to top.

A matrix is considered palindromic if every row is palindromic, every column is palindromic, and the total number of 11’s in the matrix is divisible by 44.

In one operation, you can flip any element in grid from 00 to 11 or from 11 to 00.

Return the minimum number of flips required to make grid palindromic.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 1≤m×n≤2×1051 \leq m \times n \leq 2 \times 10^5

  • 0≤0 \leq grid[i][j] ≤1\leq 1