lamps: '1' means the lamp is on, '0' means it is off.
You may perform at most one **swap**, which has two steps:
1. Switch off an entire contiguous block of lit lamps that has an unlit lamp on both its left and its right.
2. Then switch on an entire contiguous block of unlit lamps that has a lit lamp on both sides.
Treat the row as if there were an invisible lit lamp just beyond each end: these bound the dark blocks at the edges but are not counted in the answer. As a result, a lit block touching an end of the row can never be switched off.
Return the largest number of lit lamps you can end up with.lamps="0010001" → 7
Switch off the lone 1 in the middle: that leaves a dark stretch 000000 of length 6, which we then light up. The row becomes 1111111, so all 7 lamps are on.
lamps="0110" → 4
The block 11 sits between dark lamps: switch it off to get 0000, then light the whole thing, 4 lamps in total.
lamps="10" → 1
The only lit block touches the left end, so there is no dark lamp on its left and no swap is possible. One lamp stays on.
len(lamps) ≤ 10⁵lamps consists only of the characters '0' and '1'lamps="0010001"
7
Run checks the first 3 tests in your browser. Submit checks all 91 tests on the server, hidden ones included.