Given two strings: s1 and s2 with the same size, check if some permutation of string s1 can break some permutation of string s2 or vice-versa. In other words s2 can break s1 or vice-versa.
A string x can break string y (both of size n) if x[i] >= y[i] (in alphabetical order) for all i between 0 and n-1.
Input: s1 ="abc", s2 ="xya"Output: trueExplanation: "ayx"is a permutation of s2="xya" which can break to string "abc" which is a permutation of s1="abc".
Example 2:
1
2
3
Input: s1 ="abe", s2 ="acd"Output: falseExplanation: All permutations for s1="abe" are:"abe","aeb","bae","bea","eab" and "eba" and all permutation for s2="acd" are:"acd","adc","cad","cda","dac" and "dca". However, there is not any permutation from s1 which can break some permutation from s2 and vice-versa.
To determine if one permutation of s1 can break one permutation of s2 or vice versa, we need to sort both strings and compare them character by character. Here are the detailed steps:
Sort the characters of both strings.
Compare the sorted strings to check if one can break the other.
To break s2, every character in the sorted s1 should be greater than or equal to the corresponding character in the sorted s2.