Determine the minimum number of character changes needed to make a binary string satisfy the problem's definition of “beautiful.”
Problem
You are given a binary string s. You may change any character ('0' to '1' or '1' to '0') in one move.
Your task is to find the minimum number of moves required to make the string beautiful.
For this problem, a binary string is considered beautiful when it can be transformed into a valid target form by changing the fewest possible characters.
Goal
Return the minimum number of changes needed.
Notes
- A move changes exactly one character.
- The string contains only
'0'and'1'. - The intended solution is typically based on checking the string in small independent groups and counting mismatches.
Input Format
- A single binary string
s.
Output Format
- Return an integer: the minimum number of character changes needed.
Constraints
1 <= |s|sconsists only of characters'0'and'1'.- Exact official constraints are not provided in the source context.
Example 1
Input
s = "0011"
Output
0
Explanation
The string already satisfies the target form, so no changes are needed.
Example 2
Input
s = "0101"
Output
2
Explanation
Two positions must be flipped to match a valid beautiful form.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.