Suppose we have two lowercase strings s and t, they are of the same length. We can select one character from s and another from t and swap them. We can do this operation any number of times we want. Finally, we have to check whether it's possible to make the two strings same or not.
So, if the input is like s = "abcd" t = "cdab", then the output will be True
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
from collections import Counter def solve(s, t): fre = Counter(s+t) for cnt in fre.values(): if cnt % 2: return False return True s = "abcd" t = "cdab" print(solve(s, t))
"abcd", "cdab"
True