Ctrl K

Switch Lines to Darken the Board

Medium
A display is a rectangular grid of lamps board: 1 means the lamp is on, 0 means it is off. In one move you pick any row or any column and toggle every lamp in it: lit ones go dark and dark ones light up. Return True if some number of moves can turn every lamp off, and False otherwise.
Example 1
board=[[1, 0, 1], [0, 1, 0]] → True

Flip the second row to get two [1, 0, 1] rows, then flip the first and third columns.

Example 2
board=[[1, 0], [0, 0]] → False

Exactly one of the four lamps is lit. Every flip changes two cells of this 2×2 square, so the number of lit lamps stays odd and can never reach zero.

Example 3
board=[[1, 1, 1]] → True

Flipping the only row is enough.

Constraints
  • 1 ≤ len(board), len(board[0]) ≤ 300
  • All rows have the same length
  • board[i][j] is 0 or 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCheckerboard by Swapping Lines HardTurn a Square Clockwise MediumSum of Bit Differences MediumFour-Corner Rectangles MediumMagic 3×3 Blocks Medium
loading Python…
Input
board=[[1, 0, 1], [0, 1, 0]]
Expected
True

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