FunctionRacerProblemsRace

Row and Column Switches

EasyGridsPython, JavaScript, TypeScript, Java, C++

A panel of lamps has rows rows and cols columns, and every lamp starts off. Each entry of switches is either a row switch such as "R2", which flips every lamp in row 2 (a lamp that is off turns on, and one that is on turns off), or a column switch such as "C0", which flips every lamp in column 0. Rows and columns are counted from 0, and the same switch may appear more than once. Use the switches in order and return how many lamps are on at the end.

Example 1

rows 2
cols 3
switches ["R0","C1"]
returns 3

R0 turns on all three lamps of row 0. C1 then turns off the lamp in row 0, column 1 and turns on the one in row 1, column 1, which leaves 3 lamps on.

Example 2

rows 2
cols 2
switches ["R0","R1","C0","C1"]
returns 0

The two row switches turn every lamp on, and the two column switches turn every lamp off again.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Grids problems