Minimum Changes To Make Alternating Binary String

Easy

Description

Given a string s consisting only of 0s and 1s, return the minimum number of operations to make s alternating.

Examples

Input:s = "0100"
Output:1
Explanation:

Change to 0101.

Input:s = "a"
Output:0
Explanation:

A single-character string is already alternating, so 0 changes are needed.

Input:s = "10110"
Output:2
Explanation:

Changing to "10101" requires 2 changes (positions 2 and 3), while changing to "01010" requires 3 changes (positions 0, 2, and 4). The minimum is 2.

Constraints

  • 1 ≤ s.length ≤ 10^4

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!