Update appNew update is available. Click here to update.
About
30 days notice period. Strong in Data Structures and Algorithms with intuitive problem-solving skills. Proficient in Python, C/C++, SQL, Selenium, Test Case, Automation Testing, Manual Testing, Softw...
McAfee - SDET Engineer
Jaypee Institute of Information Technology, Noida 2022
My Stats
EXP gained
yellow-spark
2369
Level
5 (Champion)
Community stats
Discussions
2
Upvotes
0
Know more
37
Total problems solved
21
Easy
14
Moderate
2
Hard
0
Ninja
Jan Jan Feb Feb Mar Mar Apr Apr May May Jun Jun Jul Jul Aug Aug Sep Sep Oct Oct Nov Nov Dec Dec

Current streak:

0 days

Longest streak:

10 days

Less

More

Discussions
Easy C++ solution with comments
Interview problems

//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);         }

profile
Sandeep Kumar Yadav
Published On 03-Sep-2022
129 views
0 replies
0 upvotes