lamps[i] is 1 if the lamp is on and 0 if it is off. A stretch of consecutive lamps is flickering if no two neighbouring lamps in it are in the same state. A stretch of a single lamp is flickering too.
Return the number of flickering stretches. Two stretches are different if they differ in at least one end.lamps=[1, 1, 0, 1] → 7
The four single lamps count, plus [1, 0], [0, 1] and [1, 0, 1] at the end, for 7 in total.
lamps=[0, 0, 0] → 3
Neighbouring lamps are all equal, so only the single-lamp stretches flicker.
lamps=[1, 1, 0, 1]
7
Run checks the first 3 tests in your browser. Submit checks all 112 tests on the server, hidden ones included.