Comparator Sort

Learnings

Intuition

comp(a,b) == true 
Means a is before b is correct ordering


Now, 
if comp(a,b) == true, then comp(b,a) == false and comp(a,a) == false;

Hence 

comp(a,b){
    return a<=b 
    // Gives error, because it is confused between a->b or b->a, both returns true
}

https://leetcode.com/problems/longest-string-chain/description/?envType=daily-question&envId=2023-09-23

Last updated