LeetCode 1072, Medium. Topics: Array, Hash Table, Matrix. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 13 parametrized pytest cases, and a playground notebook:
Problem
You are given an <code>m x n</code> binary matrix <code>matrix</code>.
You can choose any number of columns in the matrix and flip every cell in that column (i.e., Change the value of the cell from <code>0</code> to <code>1</code> or vice versa).
Return <em>the maximum number of rows that have all values equal after some number of flips</em>.
Examples
Constraints
- <code>m == matrix.length</code>
- <code>n == matrix[i].length</code>
- <code>1 <= m, n <= 300</code>
- <code>matrix[i][j]</code> is either <code>0</code> or <code>1</code>.
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026