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:32:34
Glenn Greenwald
7 hours agoThe Future of Gaza With Abubaker Abed; Journalist Sam Husseini On His Physical Expulsion From Blinken’s Briefing & Biden’s Gaza Legacy | System Update #391
80.4K65 -
1:34:48
Roseanne Barr
10 hours ago $16.12 earnedWe are so F*cking Punk Rock! with Drea de Matteo | The Roseanne Barr Podcast #83
65.8K39 -
1:08:20
Man in America
11 hours ago🇨🇳 RedNote: A CCP Trojan Horse Deceiving Americans? w/ Levi Browde
27.1K32 -
3:55:11
I_Came_With_Fire_Podcast
14 hours agoTrump SABOTAGE, LA FIRE CHIEF SUED, and BIDEN’S LAST F-U!
15.1K7 -
2:59:47
Joker Effect
5 hours agoUkraine in a video game? Hardest thing I have done. S.T.A.L.K.E.R.2 Heart of Chornobyl,
56.1K4 -
1:15:22
Flyover Conservatives
1 day agoEczema, Brain Fog, B.O., and Gas… Eating Steak and Butter Creates Ultimate Health Hack - Bella, Steak and Butter Gal | FOC Show
46.2K2 -
51:58
PMG
9 hours ago $2.01 earned"Can the Government Learn from Elon Musk’s 70% Labor Cut? A Deep Dive into Inefficient Agencies"
31.7K -
6:39:15
Amish Zaku
8 hours agoRumble Spartans #10 - New Year New Maps
28.9K2 -
1:04:58
In The Litter Box w/ Jewels & Catturd
1 day agoNo Tax On Tips! | In the Litter Box w/ Jewels & Catturd – Ep. 722 – 1/17/2025
149K32 -
5:35:39
Dr Disrespect
15 hours ago🔴LIVE - DR DISRESPECT - WARZONE - CRAZY CHALLENGES
170K33