Premium Only Content
2914. Minimum Number of Changes to Make Binary String Beautiful
You are given a 0-indexed binary string s having an even length.
A string is beautiful if it's possible to partition it into one or more substrings such that:
Each substring has an even length.
Each substring contains only 1's or only 0's.
You can change any character in s to 0 or 1.
Return the minimum number of changes required to make the string s beautiful.
Example 1:
Input: s = "1001"
Output: 2
Explanation: We change s[1] to 1 and s[3] to 0 to get string "1100".
It can be seen that the string "1100" is beautiful because we can partition it into "11|00".
It can be proven that 2 is the minimum number of changes needed to make the string beautiful.
Example 2:
Input: s = "10"
Output: 1
Explanation: We change s[1] to 1 to get string "11".
It can be seen that the string "11" is beautiful because we can partition it into "11".
It can be proven that 1 is the minimum number of changes needed to make the string beautiful.
Example 3:
Input: s = "0000"
Output: 0
Explanation: We don't need to make any changes as the string "0000" is beautiful already.
Constraints:
2 <= s.length <= 105
s has an even length.
s[i] is either '0' or '1'.
class Solution {
public:
int minChanges(string s) {
int cnt=0;
int n = s.size();
for(int i=1; i<n; i += 2){
if(s[i-1] != s[i])
cnt++;
}
return cnt;
}
};
-
1:00:50
Squaring The Circle, A Randall Carlson Podcast
18 hours ago#035 Cosmic Catastrophe In The Age Of Leo - Squaring The Circle: A Randall Carlson Podcast
31.7K21 -
1:33:14
Jamie Kennedy
22 hours agoThe LA Fires...
22.3K5 -
2:01:45
Quite Frankly
1 day ago"Inauguration Eve: Trump Time Travel Review" 1/17/25
30.3K18 -
58:42
SGT Report
4 months agoYour REAL NEWS vs. CIA Mockingbird LIES -- Sam Anthony
158K95 -
2:59
LimitlessAmbition
22 hours ago $4.05 earnedPROVE THEM WRONG With This POWERFUL Motivation!
45.4K2 -
8:31:37
G2G Gaming Channel
11 hours agoGive me my Helmet, Im going in!! #RumbleGaming
71.1K1 -
4:45:11
MoFio23!
10 hours agoNintendo Switch It UP Saturdays with The Fellas: LIVE - Episode #3
44.5K6 -
6:23:10
SquallRush
8 hours agoMarvel Rivals Collab
34.4K -
8:36:24
stephengaming94
6 days agofar cry 5 live stream part 3
24.4K2 -
2:03:28
Barry Cunningham
20 hours agoTRUMP DAILY BRIEFING: 2 DAYS TO GO - ARE YOU READY FOR HISTORY TO BE MADE?
56.4K90