Row and Column Switches
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
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
The two row switches turn every lamp on, and the two column switches turn every lamp off again.
Constraints
1 <= rows, cols <= 100 <= len(switches) <= 30- each switch is
Rfollowed by a row index from 0 torows - 1, orCfollowed by a column index from 0 tocols - 1
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Grids problems
- Same Letter RegionEasy
- Stones SettleEasy
- Turns to MatchEasy
- Turtle CommandsEasy
- Up and to the RightEasy
- Wireworld StepEasy
- Crush and FallMedium
- Four in a RowMedium