'0') or black ('1'). The string fence lists the boards from left to right.
The owner wants the colours to alternate, so that no two neighbouring boards share a colour. One action repaints a single board in the other colour. Return the minimum number of repaints.fence="00110" → 2
Repainting the second and the fourth boards gives "01010", which takes 2 repaints. Reaching "10101" would take 3.
fence="1010" → 0
The colours already alternate, so nothing needs repainting.
fence="000" → 1
fence contains only the characters '0' and '1'fence="00110"
2
Run checks the first 3 tests in your browser. Submit checks all 120 tests on the server, hidden ones included.