You are given two strings s1 and s2 of equal length, where each string contains only the characters 'x' and 'y'. Your goal is to make both strings identical by performing the minimum number of character swaps.
The twist? You can only swap characters that belong to different strings. That is, you can swap s1[i] with s2[j] for any valid indices i and j.
Your task: Return the minimum number of swaps required to make s1 and s2 equal, or return -1 if it's impossible.
Example: If s1 = "xx" and s2 = "yy", you can swap s1[0] with s2[0] to get s1 = "yx" and s2 = "xy", then swap s1[1] with s2[0] to get both strings as "xx" or "yy".
Input & Output
Visualization
Time & Space Complexity
Single pass through both strings to count mismatch patterns
Only using constant extra space for counters
Constraints
- 1 โค s1.length, s2.length โค 1000
- s1.length == s2.length
- s1[i] and s2[i] are either 'x' or 'y'
- Both strings contain only characters 'x' and 'y'