rows rows and cols columns, all starting at zero. An operator presses buttons; a press presses[i] = [r, c] adds 1 to every counter in row r and to every counter in column c (the counter where they cross gains 2). Rows and columns are numbered from zero.
Return how many counters show an odd number once all the presses are done.
Simulating it directly is easy; see if you can get by with O(rows + cols) memory and without walking the whole grid.rows=3, cols=3, presses=[[1, 2]] → 4
Row 1 and column 2 each gain 1, and the cell they share gains 2. That leaves 2 + 2 = 4 odd cells.
rows=2, cols=4, presses=[[0, 0], [0, 3]] → 4
Row 0 is pressed twice and ends up even; columns 0 and 3 are pressed once each, so both full columns are odd: 4 cells.
rows=1, cols=5, presses=[[0, 4]] → 4
rows=3, cols=3, presses=[[1, 2]]
4
Run checks the first 3 tests in your browser. Submit checks all 78 tests on the server, hidden ones included.