bits of zeros and ones. You may change it in two ways, in any order and as many times as you like:
- **rotate**: take the first character off and append it to the end; this is free;
- **flip**: replace any single character with the opposite one (0 with 1 or 1 with 0).
A string is alternating if no two neighbouring characters are equal, like "1010" or "01010".
Return the smallest number of flips needed to make the string alternating.bits="110" → 0
Moving the first character to the end gives "101", so no flips are needed.
bits="0010" → 1
Flipping the first character gives "1010". Zero flips is impossible: an alternating string of length 4 has exactly two 1s.
bits="11100" → 1
bits contains only the characters 0 and 1bits="110"
0
Run checks the first 3 tests in your browser. Submit checks all 156 tests on the server, hidden ones included.