In one operation you may flip any single character (0 becomes 1 or 1 becomes 0).
Return the minimum number of flips needed so that s can be partitioned into contiguous blocks where every block has even length and every block consists of a single repeated character (all 0s or all 1s). Blocks may have different lengths.
Examples
Example 1
Input: s = "1001"
Output: 2
Explanation: Flipping the middle two characters gives "1111", one valid block. No single flip suffices.
Example 2
Input: s = "0011"
Output: 0
Explanation: "00" + "11" is already a valid partition.
Example 3
Input: s = "10"
Output: 1
Explanation: Flip either character: "11" or "00".
Constraints
2≤s.length≤105; s.length is even.
s consists only of 0 and 1.
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up