We’re preparing your current view and syncing the latest data.
Minimum Number of Flips to Make Binary String Alternating
gfgYou are given a binary string s. You can perform any number of flips on s. In one flip, you can change any '0' to '1' or any '1' to '0'. Return the minimum number of flips needed to make s alternating (no two adjacent characters are the same). For example, "0101" and "1010" are alternating strings.
A single line containing the binary string s.
An integer representing the minimum number of flips required to make s alternating.
1 <= s.length <= 10^5 s[i] is either '0' or '1'.
Example 1
Input
"111000"
Output
2
Explanation
Flip the second and fifth characters to get "101010" or "010101".
Example 2
Input
"010"
Output
0
Explanation
The string is already alternating.
Example 3
Input
"1110"
Output
1
Explanation
Flip the second character to get "1010".