Class Solution
- java.lang.Object
-
- g1401_1500.s1433_check_if_a_string_can_break_another_string.Solution
-
public class Solution extends Object
1433 - Check If a String Can Break Another String.Medium
Given two strings:
s1ands2with the same size, check if some permutation of strings1can break some permutation of strings2or vice-versa. In other wordss2can breaks1or vice-versa.A string
xcan break stringy(both of sizen) ifx[i] >= y[i](in alphabetical order) for allibetween0andn-1.Example 1:
Input: s1 = “abc”, s2 = “xya”
Output: true
Explanation: “ayx” is a permutation of s2=“xya” which can break to string “abc” which is a permutation of s1=“abc”.
Example 2:
Input: s1 = “abe”, s2 = “acd”
Output: false
Explanation: 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.
Example 3:
Input: s1 = “leetcodee”, s2 = “interview”
Output: true
Constraints:
s1.length == ns2.length == n1 <= n <= 10^5- All strings consist of lowercase English letters.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-