Current streak:
0 days
Longest streak:
10 days
Less
More
//There are only two possibilities either string will start with 0 or 1;
int makeBeautiful(string str) { // Write your code here int n=str.length(); int res1=0,res2=0;
// Loop to count no. of flip required to make string beautiful when start with 0; for(int i=0; i<n; i++) { if(i%2==0) { if(str[i]!='0') res1++; } if(i%2!=0) { if(str[i]!='1') res1++; } }
// Loop to count no. of flip required to make string beautiful when start with 1; for(int i=0; i<n; i++) { if(i%2==0) { if(str[i]!='1') res2++; } if(i%2!=0) { if(str[i]!='0') res2++; } } return min(res1,res2); }