Description
You are given an m x n binary matrix. You can choose any number of columns and flip every cell in that column. Return the maximum number of rows that have all values equal after some number of flips.
Examples
Input:
matrix = [[0,1],[1,1]]Output:
1Explanation:
One row can be all equal.
Input:
matrix = [[1]]Output:
1Explanation:
Minimal case with a single-element matrix.
Input:
matrix = [[0,0,0],[1,1,1],[0,1,0]]Output:
2Explanation:
Flip column 1 (middle column) to get [[0,1,0],[1,0,1],[0,0,0]]. Now rows 0 and 2 both have the pattern [0,1,0] and [0,0,0] respectively, but it is possible to't make all three rows identical. However, if flipping columns 0 and 2, this gives [[1,0,1],[0,1,0],[1,1,1]]. The maximum it is possible to achieve is 2 rows with all equal values by making rows 0 and 2 both become [1,1,1] after flipping columns 0 and 1.
Constraints
- •
m == matrix.length - •
n == matrix[i].length - •
1 ≤ m, n ≤ 300