Given a binary string s, return the minimum number of character swaps to make it alternating, or -1 if it is impossible.

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

Any two characters may be swapped, even if they are&nbsp;not adjacent.

&nbsp;
Example 1:

Input: s = "111000"
Output: 1
Explanation: Swap positions 1 and 4: "111000" -&gt; "101010"
The string is now alternating.


Example 2:

Input: s = "010"
Output: 0
Explanation: The string is already alternating, no swaps are needed.


Example 3:

Input: s = "1110"
Output: -1


&nbsp;
Constraints:


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


class Solution:
def minSwaps(self, st: str) -> int:
    
    def swap(st,c):
        n = len(st)
        mis = 0
        for i in range(n):
            if i%2==0 and st[i]!=c:
                mis+=1
            if i%2==1 and st[i]==c:
                mis+=1
        return mis//2
            
    dic = Counter(st)
    z = dic['0']
    o = dic['1']
    res=0
    if abs(z-o)>1:
        return -1
    elif z>o:
        res = swap(st,'0')
    elif o>z:
        res = swap(st,'1')
    else:
        res = min(swap(st,'0'),swap(st,'1'))
    
    return res
class Solution {
    public int minSwaps(String s) {
        int cntZero=0 , cntOne=0;
        for(char ch:s.toCharArray()){
            if(ch=='0') cntZero++;
            else cntOne++;
        }
        
        //Invalid
        if(Math.abs(cntOne-cntZero)>1) return -1;
        
        
        if(cntOne>cntZero){  //one must be at even posotion
            return countSwaps(s,'1');    
        }else if(cntOne<cntZero){
            return countSwaps(s,'0'); //zero must be at even position
        }
        
        return Math.min(countSwaps(s,'0'),countSwaps(s,'1'));    
    }
    
    //wrong count 
    private int countSwaps(String s,char start){
        int wrongPosition=0;
        for(int i=0;i<s.length();i+=2){
            if(s.charAt(i)!=start) wrongPosition++;
        }
        return wrongPosition;
    }
} 
class Solution {
    
    int minFillPos(string& s, char ch, int current = 0) {
        int count = 0;
        for(int i=0; i<s.size(); i+=2) {
            if(s[i] != ch) count++;
        }
        return count;
    }
    
public:
    int minSwaps(string s) {
        int oneCount = count(s.begin(), s.end(), '1');
        int zeroCount = count(s.begin(), s.end(), '0');
        if(abs(oneCount-zeroCount) > 1) return -1;
        if(oneCount > zeroCount) return minFillPos(s,'1');
        if(zeroCount > oneCount) return minFillPos(s,'0');
        return min(minFillPos(s,'0'), minFillPos(s,'1'));
    }
};
var minSwaps = function(s) {
    let ones = 0;
    let zeroes = 0;
    
    for(let c of s) {
        if(c === "1") ones++
        else zeroes++
    }
    
    if(Math.abs(ones - zeroes) > 1) return -1
    
    function count(i) {
        let res = 0
        for(let c of s) {
            if(i !== c) res++;
            if(i === "1") i = "0";
            else i = "1";
        }
        
        return res/2;
    };
    
    if(ones > zeroes) return count("1")
    if(zeroes > ones) return count("0")

    return Math.min(count("1"), count("0"));
};
Minimum Number of Swaps to Make the Binary String Alternating