Problem
Ask
Submissions

Problem: Minimum Flips to Make the Binary String Alternate

Medium
30 min
Understand and implement an algorithm to determine the minimum number of bit flips required to convert a binary string into an alternating pattern. Practice optimizing your solution to run efficiently in linear time and constant space, reinforcing skills in algorithm design and problem solving.

Statement

Given a binary string s, the following two operations can be performed in any sequence:

  • Type–1: Remove the character at the start of the string s and append it to the end of the string.

  • Type–2: Pick any character from the string and flip its value. in other words, if its value is 00, it becomes 11 and vice versa.

Your task is to return the minimum number of type-22 operations that you need to perform before s becomes alternating.

Note: The string is called alternating if no two adjacent characters are equal.

Constraints:

  • 11 \leq s.length 105\leq 10^5
  • s[i] is either 00 or 11.
Problem
Ask
Submissions

Problem: Minimum Flips to Make the Binary String Alternate

Medium
30 min
Understand and implement an algorithm to determine the minimum number of bit flips required to convert a binary string into an alternating pattern. Practice optimizing your solution to run efficiently in linear time and constant space, reinforcing skills in algorithm design and problem solving.

Statement

Given a binary string s, the following two operations can be performed in any sequence:

  • Type–1: Remove the character at the start of the string s and append it to the end of the string.

  • Type–2: Pick any character from the string and flip its value. in other words, if its value is 00, it becomes 11 and vice versa.

Your task is to return the minimum number of type-22 operations that you need to perform before s becomes alternating.

Note: The string is called alternating if no two adjacent characters are equal.

Constraints:

  • 11 \leq s.length 105\leq 10^5
  • s[i] is either 00 or 11.