Ctrl K

Uniform Rows After Column Flips

Medium
A light board is a grid grid of m rows and n columns: 1 means the bulb is on, 0 means it is off. Each column has its own switch that toggles every bulb in that column. You may press any switches, each as many times as you like. A row is uniform when its bulbs are all on or all off. Return the largest number of uniform rows you can get.
Example 1
grid=[[1, 0, 1], [0, 1, 0], [1, 1, 1]] → 2

Flip the middle column: the rows become [1, 1, 1], [0, 0, 0] and [1, 0, 1], so two are uniform.

Example 2
grid=[[0, 1], [0, 0]] → 1

The rows are neither equal nor opposite, so only one of them can be made uniform.

Example 3
grid=[[1, 0, 0, 1], [0, 1, 1, 0], [1, 0, 0, 1]] → 3

Flip columns 1 and 2: all three rows become uniform.

Constraints
  • 1 ≤ m, n ≤ 300
  • grid[i][j] is 0 or 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSudoku Board Without Clashes MediumZero Out the Crosses MediumMultiply Mostly-Zero Matrices MediumLonely Dark Pixels MediumDark Pixels in Twin Rows Medium
loading Python…
Input
grid=[[1, 0, 1], [0, 1, 0], [1, 1, 1]]
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 90 tests on the server, hidden ones included.