Practice Minimum Swaps to Make Strings Equal
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
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.
Source: Minimum Swaps to Make Strings Equal on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s1 = "xx", s2 = "yy"
1
# Example 2
s1 = "xy", s2 = "yx"
2
# Example 3
s1 = "xx", s2 = "xy"
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Swaps to Make Strings Equal.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.