Suppose we have two strings s and t of the same size, we have to check whether there is some permutation of s, say s1, and permutation of t, say t1, such that: s1[i] ≤ t1[i] for all 0 ≤ i < n or t1[i] ≤ s1[i] for all 0 ≤ i < n.
So, if the input is like s = "vyx" t = "wzx", then the output will be True, as we can have s1 = "vxy" and t1 = "wxz".
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): if not len(s) or not len(t): return True s = sorted(s) t = sorted(t) def util(s1, t1): for i in range(len(s1)): if s1[i] > t1[i]: return False return True if util(s, t): return True s, t = t, s return util(s, t) ob = Solution() s = "vyx" t = "wzx" print(ob.solve(s, t))