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.<p>Medium</p> <p>Given two strings: <code>s1</code> and <code>s2</code> with the same size, check if some permutation of string <code>s1</code> can break some permutation of string <code>s2</code> or vice-versa. In other words <code>s2</code> can break <code>s1</code> or vice-versa.</p> <p>A string <code>x</code> can break string <code>y</code> (both of size <code>n</code>) if <code>x[i] >= y[i]</code> (in alphabetical order) for all <code>i</code> between <code>0</code> and <code>n-1</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s1 = &ldquo;abc&rdquo;, s2 = &ldquo;xya&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> &ldquo;ayx&rdquo; is a permutation of s2=&ldquo;xya&rdquo; which can break to string &ldquo;abc&rdquo; which is a permutation of s1=&ldquo;abc&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s1 = &ldquo;abe&rdquo;, s2 = &ldquo;acd&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> All permutations for s1=&ldquo;abe&rdquo; are: &ldquo;abe&rdquo;, &ldquo;aeb&rdquo;, &ldquo;bae&rdquo;, &ldquo;bea&rdquo;, &ldquo;eab&rdquo; and &ldquo;eba&rdquo; and all permutation for s2=&ldquo;acd&rdquo; are: &ldquo;acd&rdquo;, &ldquo;adc&rdquo;, &ldquo;cad&rdquo;, &ldquo;cda&rdquo;, &ldquo;dac&rdquo; and &ldquo;dca&rdquo;. However, there is not any permutation from s1 which can break some permutation from s2 and vice-versa.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s1 = &ldquo;leetcodee&rdquo;, s2 = &ldquo;interview&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Constraints:</strong></p> <ul> <li><code>s1.length == n</code></li> <li><code>s2.length == n</code></li> <li><code>1 <= n <= 10^5</code></li> <li>All strings consist of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • checkIfCanBreak

      public boolean checkIfCanBreak(String s1, String s2)