Trains the technique from
LeetCode 1758Minimum Changes To Make Alternating Binary StringThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A strip of cells reads s, a string of '0' and '1'. One flip changes a single cell to the other character.
The strip is striped when no two neighbouring cells hold the same character. Return the fewest flips that leave the strip striped.
Example 1
Aiming for the strip that starts with a one leaves five cells wrong, and aiming for the other leaves five as well, so five flips is the best either way.
Example 2
Against the version starting with a one, the cells at positions 1, 3, 5, 7 are wrong, which is four flips. The other version needs five.
Example 3
The strip already alternates, so nothing needs flipping.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def min_operations(s: str) -> int:public int minOperations(String s)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.