3240. Minimum Number of Flips to Make Binary Grid Palindromic II
3240. Minimum Number of Flips to Make Binary Grid Palindromic II
Description
You are given an m x n
binary matrix grid
.
A row or column is considered palindromic if its values read the same forward and backward.
You can flip any number of cells in grid
from 0
to 1
, or from 1
to 0
.
Return the minimum number of cells that need to be flipped to make all rows and columns palindromic , and the total number of 1
âs in grid
divisible by 4
.
Example 1:
1 | Input: grid = [[1,0,0],[0,1,0],[0,0,1]] |
Explanation:
![](https://assets.leetcode.com/uploads/2024/08/01/image.png)
Example 2:
1 | Input: grid = [[0,1],[0,1],[0,0]] |
Explanation:
![](https://assets.leetcode.com/uploads/2024/07/08/screenshot-from-2024-07-09-01-37-48.png)
Example 3:
1 | Input: grid = [[1],[1]] |
Explanation:
![](https://assets.leetcode.com/uploads/2024/08/01/screenshot-from-2024-08-01-23-05-26.png)
Constraints:
m == grid.length
n == grid[i].length
1 <= m * n <= 2 * 10^5
0 <= grid[i][j] <= 1
Hints/Notes
- 2024/08/04
- draw the grid
- 0x3Fâs solution(checked)
- Biweekly Contest 136
Solution
Language: C++
1 | class Solution { |