top and bottom of equal length, made of the letters x and y. Your goal is to make them identical.
In one move you pick any character of top and any character of bottom and exchange them: top[i] ↔ bottom[j], where i and j may differ. Swapping two characters within the same string is not allowed.
Return the smallest number of moves after which the strings match, or -1 if that is impossible.top="xy", bottom="yx" → 2
Two mismatches of different kinds. First swap top[0] with bottom[0] to get "yy" and "xx", then swap top[0] with bottom[1]: both strings read "xy". Two swaps in total.
top="xxyx", bottom="yyyx" → 1
Positions 0 and 1 differ, both with x on top and y below. A single swap of top[0] and bottom[1] turns both strings into "yxyx".
top="xy", bottom="xx" → -1
There are three x letters in total, an odd number, so they cannot be split evenly between the strings.
x and ytop="xy", bottom="yx"
2
Run checks the first 3 tests in your browser. Submit checks all 106 tests on the server, hidden ones included.