You are given a string s consisting only of the characters '0' and '1'. In one operation, you can change any '0' to '1' or vice versa.
The string is called alternating if no two adjacent characters are equal. For example, the string "010" is alternating, while the string "0100" is not.
Your goal is to transform the given binary string into an alternating pattern using the minimum number of operations. An alternating pattern means characters alternate between '0' and '1' throughout the string.
Return the minimum number of operations needed to make s alternating.
Key Insight: There are only two possible alternating patterns for any string - one starting with '0' (like "010101...") and one starting with '1' (like "101010..."). The answer is the minimum changes needed for either pattern.
Input & Output
Constraints
- 1 โค s.length โค 104
- s[i] is either '0' or '1'