You are given a string s consisting only of the characters '0' and '1'. In one operation, you can change any '0' to '1' or vice versa.

The string is called alternating if no two adjacent characters are equal. For example, the string "010" is alternating, while the string "0100" is not.

Return the minimum number of operations needed to make s alternating.

&nbsp;
Example 1:

Input: s = "0100"
Output: 1
Explanation: If you change the last character to '1', s will be "0101", which is alternating.


Example 2:

Input: s = "10"
Output: 0
Explanation: s is already alternating.


Example 3:

Input: s = "1111"
Output: 2
Explanation: You need two operations to reach "0101" or "1010".


&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 104
	s[i] is either '0' or '1'.


class Solution:
    def minOperations(self, s: str) -> int:
        count = 0
        count1 = 0
        for i in range(len(s)):
            if i % 2 == 0:
                if s[i] == '1':
                    count += 1
                if s[i] == '0':
                    count1 += 1
            else:
                if s[i] == '0':
                    count += 1
                if s[i] == '1':
                    count1 += 1
        return min(count, count1)
class Solution {
    public int minOperations(String s) {
        int count0 = 0; // changes required when the string starts from 0
        int count1 = 0; // changes required when the string starts from 1

        for(int i = 0; i < s.length(); i++){

            // string starts with 1 => all chars at even places should be 1 and that at odd places should be 0
            if((i % 2 == 0 && s.charAt(i) == '0') || (i % 2 != 0 && s.charAt(i) == '1'))
                count1++;

            // string starts with 0 => all chars at even places should be 0 and that at odd places should be 1
            else if((i % 2 == 0 && s.charAt(i) == '1') || (i % 2 != 0 && s.charAt(i) == '0'))
                count0++;
        }

        // return minimum of the two
        return Math.min(count0, count1);
    }
}
class Solution {
public:
    int minOperations(string s) {
        int n=s.size(), ans=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]-'0' != i%2)
            ans++;
        }
        return min(ans, n-ans);
    }
};
/**
 * @param {string} s
 * @return {number}
 */
var minOperations = function(s) {
    let counter1=0;
    let counter2=0;
    for(let i=0;i<s.length;i++){
        if(i%2===0){
            if(s[i]==="0"){
                counter1++;
            }
            if(s[i]==="1"){
                counter2++;
            }
        }
        if(i%2===1){
            if(s[i]==="1"){
                counter1++;
            }
            if(s[i]==="0"){
                counter2++;
            }
        }
    }
    return Math.min(counter1,counter2);
};
Minimum Changes To Make Alternating Binary String