We’re preparing your current view and syncing the latest data.
Minimum Operations to Make Binary String Equal
gfgYou are given a binary string s (a string consisting of characters '0' and '1'). In one operation, you can flip a character (change '0' to '1' or '1' to '0'). Your goal is to find the minimum number of operations required to make all characters in the string equal (all '0's or all '1's). Return the minimum number of operations needed.
A single line containing the binary string s.
An integer representing the minimum number of flips required to make all characters equal.
1 <= s.length <= 10^5 s consists only of '0' and '1' characters.
Example 1
Input
00110
Output
2
Explanation
Flip the two '1's at positions 3 and 4 to '0's, resulting in "00000".
Example 2
Input
0100
Output
1
Explanation
Flip the '1' at position 2 to '0', resulting in "0000".