Skip to content
LC-0861 Medium LeetCode

861. Score After Flipping Matrix

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 80% Topics: Array, Greedy, Bit Manipulation, Matrix
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(r * c)
# Space: O(1)


class Solution(object):
    def matrixScore(self, A):
        """
        :type A: List[List[int]]
        :rtype: int
        """
        R, C = len(A), len(A[0])
        result = 0
        for c in xrange(C):
            col = 0
            for r in xrange(R):
                col += A[r][c] ^ A[r][0]
            result += max(col, R-col) * 2**(C-1-c)
        return result

Solution from kamyu104/LeetCode-Solutions · MIT