Check If a String Can Break Another String

Medium

Description

Two strings can break if one can be rearranged so it's >= other character by character. Return true if either can break the other.

Examples

Input:s1 = "abc", s2 = "xya"
Output:true
Explanation:

abc breaks xya.

Input:s1 = "abe", s2 = "acd"
Output:false
Explanation:

For s1 = "abe", s2 = "acd", the answer is false because the check if a string can break another string condition is not met.

Input:s1 = "leetcode", s2 = "interview"
Output:true
Explanation:

After sorting s1 becomes "cdeeeolt" and s2 becomes "eeeiinrtv". Comparing character by character: 'c'≥'e' is false, but 'e'≥'e', 'e'≥'e', 'e'≥'i', 'e'≥'i', 'o'≥'n', 'l'≥'r', 't'≥'t', 'v' has no pair. Since s2 can break s1 (each character in sorted s2 is ≥ corresponding character in sorted s1), the answer is true.

Constraints

  • 1 ≤ s1.length ≤ 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!