Minimum Flips to Make the Binary String Alternate

Try to solve the Minimum Flips to Make the Binary String Alternate problem.

Statement

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

  • Remove the character at the start of the string s and append it to the end of the string.

  • 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:

  • 1≤1 \leq s.length ≤103\leq 10^3
  • s[i] is either 00 or 11.

Examples

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.