Minimum Swaps to Make Strings Equal
Problem statement
You are given two equal-length strings first and second containing only 'x' and 'y'. In one operation, choose one position from each string and swap those two characters.
Return the minimum operations needed to make the strings equal, or -1 if it is impossible.
Function
minimumSwap(first: String, second: String) → intExamples
Example 1
first = "xx"second = "yy"return = 1Swap one x with one y across the strings.
Example 2
first = "xy"second = "yx"return = 2The two opposite mismatch types require two swaps.
Constraints
1 <= first.length == second.length <= 10^5.- Both strings contain only
'x'and'y'.