You are given two strings s1 and s2 of equal length consisting of letters "x" and "y" only. Your task is to make these two strings equal to each other. You can swap any two characters that belong to different strings, which means: swap s1[i] and s2[j].

Return the minimum number of swaps required to make s1 and s2 equal, or return -1 if it is impossible to do so.

&nbsp;
Example 1:

Input: s1 = "xx", s2 = "yy"
Output: 1
Explanation: Swap s1[0] and s2[1], s1 = "yx", s2 = "yx".


Example 2:

Input: s1 = "xy", s2 = "yx"
Output: 2
Explanation: Swap s1[0] and s2[0], s1 = "yy", s2 = "xx".
Swap s1[0] and s2[1], s1 = "xy", s2 = "xy".
Note that you cannot swap s1[0] and s1[1] to make s1 equal to "yx", cause we can only swap chars in different strings.


Example 3:

Input: s1 = "xx", s2 = "xy"
Output: -1


&nbsp;
Constraints:


	1 &lt;= s1.length, s2.length &lt;= 1000
	s1, s2 only contain 'x' or 'y'.


class Solution:
    def minimumSwap(self, s1: str, s2: str) -> int:
        h = defaultdict(int)
        count = 0    # variable to keep track of the number of mismatches; it is impossible to make strings equal if count is odd
        for i in range(len(s1)):
            if s1[i] != s2[i]:
                count += 1
                h[s1[i]] += 1
        if count % 2 != 0:     
            return -1
        res, a, b = 0, h['x'], h['y']
        res += a // 2 + b // 2
        if a % 2 == 0:
            return res
        return res + 2
class Solution {
    public int minimumSwap(String s1, String s2) {
        if(s1.length() != s2.length()) return -1;
		int n = s1.length();
        int x = 0 , y = 0;
        
        for(int i = 0 ; i < n ; i ++){
            char c1 = s1.charAt(i) , c2 = s2.charAt(i);
            if(c1 == 'x' && c2 == 'y') x++;
            else if(c1 == 'y' && c2 == 'x') y++;
        }
        
        if(x % 2 == 0 && y % 2 == 0) return x/2 + y/2;
        else if(x % 2 == 1 && y % 2 == 1) return x/2 + y/2 + 2;
        return -1;
    }
}
class Solution {
public:
    int minimumSwap(string s1, string s2) {
        int n = s1.size();
        int cnt1=0,cnt2=0,i=0;
        
        while(i<n){
            int x = s1[i];
            int y = s2[i++];
            if(x=='x' and y=='y') cnt1++;
            if(x=='y' and y=='x') cnt2++;
        }
        
        if((cnt1+cnt2)%2==1) return -1;
        
        return (cnt1/2) + (cnt2/2) + (cnt1%2 + cnt2%2);
    }
};
var minimumSwap = function(s1, s2) {
   let count1 = 0;
    let count2 = 0;
   for(let i in s1) {
       if(s1[i] === "x" && s2[i] === "y") {
           count1++
       }
        if(s1[i] === "y" && s2[i] === "x") {
           count2++
       }
   }

    let ans = Math.floor(count1 / 2) + Math.floor(count2 / 2);
    if(count1 % 2 === 0 && count2 % 2 === 0){
        return ans
    }
    else if(count1 % 2 !== 0 && count2 % 2 !== 0){
        return ans + 2;
    }
    else {
        return -1;
    }
};
Minimum Swaps to Make Strings Equal