bits and an integer flips. At most flips times you may pick any character and flip it, turning 0 into 1 or vice versa.
A run is a stretch of consecutive equal characters. Flip characters so that the longest run in the string is as short as possible, and return its length.bits="000000", flips=2 → 2
Flip positions 2 and 5 to get 001001, whose longest run is 2. Two flips are not enough to get every run down to 1.
bits="1110111", flips=1 → 3
One flip can break only one of the two 111 runs; the other stays. The answer is 3.
bits="0110", flips=2 → 1
bits) ≤ 10⁵bits consists only of 0 and 1flips ≤ len(bits)bits="000000", flips=2
2
Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.