Suppose we have two strings s and t of length n. We can take one character from s and another from t and swap them. We can make unlimited number of swaps; we have to check whether it's possible to make the two strings equal or not.
So, if the input is like s = "xy", t = "yx", then the output will be True
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
class Solution: def solve(self, s, t): st=sorted(s+t) for i in range(0,len(st),2): if st[i]!=st[i+1]: return False return True ob = Solution() print(ob.solve("xy", "yx"))