Loading...
You are given a binary string s of even length.
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.
Input: s = "1001"
Output: 2
Explanation: Flipping the middle two characters gives "1111", one valid block. No single flip suffices.
Input: s = "0011"
Output: 0
Explanation: "00" + "11" is already a valid partition.
Input: s = "10"
Output: 1
Explanation: Flip either character: "11" or "00".
s.length ≤105; s.length is even.s consists only of 0 and 1.Click "Run" to test with sample cases or "Submit" to run all tests.