Skip to content
Decoder

Score After Flipping Matrix

Medium

Problem

grid is an m x n matrix of 0s and 1s. A move toggles every cell in one row or one column (0 becomes 1, 1 becomes 0). After any number of moves, read each row as a binary number and add them up. Return the highest possible score.

Example 1

grid = [[0, 0, 1, 1],

Example 2

        [1, 0, 1, 0],

Example 3

Input
[1, 1, 0, 0]]
Output
39
Why
1111 + 1001 + 1111 = 15 + 9 + 15

Constraints

  • m == grid.length
  • n == grid[i].length
  • 1 <= m, n <= 20
  • grid[i][j] is 0 or 1.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.