Problem statement

https://binarysearch.com/problems/Column-Flips-to-Maximum-Number-of-Equal-Rows/

Solution

Equal to Leetcode 1072. Flip Columns For Maximum Number of Equal Rows.

Complexity

It is O(mn) for time and space.

Code

class Solution:
    def solve(self, M):
        cnt = Counter()
        for row in M:
            if row[0] == 1:
                row = [1 - x for x in row]
            cnt[tuple(row)] += 1
        
        return max(cnt.values())