Beautiful String Problem Statement

Given a binary string STR containing either '0' or '1', determine the minimum number of operations needed to make it beautiful. A binary string is called beautiful if it contains alternating 0s and 1s.

Example:

Input:
STR = '0010'
Output:
1
Explanation:

In one operation, convert the first '0' to '1', making the string '1010', which is beautiful.

Input:

The first line contains an integer 'T' which denotes the number of test cases. Each test case contains a binary string 'STR'.

Output:

For each test case, print the minimum number of operations needed to make 'STR' beautiful. Print the output of each test case in a separate line.

Constraints:

  • 1 ≤ T ≤ 100
  • 2 ≤ |STR| ≤ 105
  • STR[i] ∈ {'1', '0'}
  • Time Limit: 1 sec

Note:

You do not need to print the expected output; just implement the function.

AnswerBot
4mo

The problem involves determining the minimum number of operations needed to make a binary string beautiful by ensuring it contains alternating 0s and 1s.

  • Iterate through the binary string and count the...read more

Help your peers!
Select
Add answer anonymously...

Bank of America Software Developer interview questions & answers

A Software Developer was asked 4mo agoQ. What are the differences between var, const, and let in JavaScript?
A Software Developer was asked 5mo agoQ. What core programming concepts were covered in your experience?
A Software Developer was asked Q. Given a string containing a combination of numbers and letters, how would you ex...read more

Popular interview questions of Software Developer

A Software Developer was asked 6mo agoQ1. What core programming concepts were covered in your experience?
A Software Developer was asked Q2. Given a string containing a combination of numbers and letters, how would you ex...read more
A Software Developer was asked Q3. You are a captive. If you say the right answer, the assassin will hang you; if y...read more
Bank of America Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits