Given two strings: s1 and s2 with the same&nbsp;size, check if some&nbsp;permutation of string s1 can break&nbsp;some&nbsp;permutation of string s2 or vice-versa. In other words s2 can break s1&nbsp;or vice-versa.

A string x&nbsp;can break&nbsp;string y&nbsp;(both of size n) if x[i] &gt;= y[i]&nbsp;(in alphabetical order)&nbsp;for all i&nbsp;between 0 and n-1.

&nbsp;
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


&nbsp;
Constraints:


	s1.length == n
	s2.length == n
	1 &lt;= n &lt;= 10^5
	All strings consist of lowercase English letters.


class Solution:
    def checkIfCanBreak(self, s1: str, s2: str) -> bool:
        s1, s2 = sorted(s1), sorted(s2)
        return all(a1 >= a2 for a1, a2 in zip(s1, s2)) or all(a1 <= a2 for a1, a2 in zip(s1, s2))
class Solution {
    public boolean checkIfCanBreak(String s1, String s2) {
        int n = s1.length();
        char[] one = s1.toCharArray();
        char[] two = s2.toCharArray();
        Arrays.sort(one);
        Arrays.sort(two);
        if(check(one,two,n) || check(two,one,n)){
            return true;
        }
        return false;
    }
    public boolean check(char[] one,char[] two,int n){
        for(int i=0;i<n;i++){
            if(one[i]-'a'>two[i]-'a'){
                return false;
            }
        }
        return true;
    }
}
class Solution {
public:

    bool checkIfCanBreak(string s1, string s2)
    {
       vector<int>freq1(26,0),freq2(26,0);
        for(int i=0;i<s1.size();i++)
        {
            freq1[s1[i]-'a']++;
        }
        for(int i=0;i<s2.size();i++)
        {
            freq2[s2[i]-'a']++;
        }
        int count1 =0,count2=0;
        bool check1 = true,check2=true;
        for(int i=0;i<25;i++)
        {
            count1 += freq1[i]-freq2[i];
            count2 += freq2[i] - freq1[i];
            if(count1<0)
            {
                check1 = false;
            }
            if(count2<0)
            {
                check2 = false;
            }
            if(count1<0 && count2<0)
            {
                break;
            }
        }
        return check1 || check2;
    }
};
const canAbreakB = (s1, s2) => {
    const s1Heap = new MinPriorityQueue();
    const s2Heap = new MinPriorityQueue();
    
    for(let c of s1) {
        s1Heap.enqueue(c.charCodeAt(0));
    }
    
    for(let c of s2) {
        s2Heap.enqueue(c.charCodeAt(0));
    }
    
    while(s2Heap.size()) {
        const s1Least = s1Heap.dequeue().element;
        const s2Least = s2Heap.dequeue().element;
        if(s1Least > s2Least) {
            return false;
        }
    }
    return true;
}

var checkIfCanBreak = function(s1, s2) {
    return canAbreakB(s1, s2) || canAbreakB(s2, s1);
};
Check If a String Can Break Another String