Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2021-11-09_14-51-47.png
50 KB
#medium

#N1433. Check If a String Can Break Another String
problem link

#solution
class Solution {
public boolean checkIfCanBreak(String s1, String s2) {
char arr1[]=s1.toCharArray();
char arr2[]=s2.toCharArray();

Arrays.sort(arr1);
Arrays.sort(arr2);

int count1=0, count2=0, l=s1.length();

for(int i=0; i<l; i++){
if(arr1[i]>=arr2[i])
count1++;
if(arr2[i]>=arr1[i])
count2++;
}

return count1==l||count2==l;
}
}