FastPrepFastPrep
Problem Brief

Minimum Operations to Make Alternating Binary String

INTERNOA

You are given a binary string. Transform it into an alternating binary string using the following operation: select any bit and flip it (change 0 to 1 or 1 to 0).

Find the minimum number of operations required to make the string alternating.

1Example 1

Input
s = "11101"
Output
1
Explanation

Flipping the bit at index 1 (0-based indexing) makes the string "10101", which is alternating. So the minimum operations is 1.

2Example 2

Input
s = "111101"
Output
2
Explanation

Flip the 1st and 3rd characters (1-based indexing) to obtain "101010", which is alternating. Thus, the minimum operations is 2.

Constraints

Limits and guarantees your solution can rely on.

  • 0 ≤ length of s ≤ 2 * 10^5
  • s consists only of characters '0' and '1'
public int solveBinaryString(String s) {
  // write your code here
}
Input

s

"11101"

Output

1

Sign in to submit your solution.