Leetcode 1147 Solution

This article provides solution to leetcode question 1147 (flip-columns-for-maximum-number-of-equal-rows)

https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows

Solution

class Solution:
    def maxEqualRowsAfterFlips(self, matrix: List[List[int]]) -> int:
        m = collections.defaultdict(int)

        ans = 0
        for row in matrix:
            s = "".join([str(cell ^ row[0]) for cell in row])
            m[s] += 1
            ans = max(ans, m[s])

        return ans