NZEC using comparator but AC using comparable interface

I got ac using Comparable interface which I used for sorting but using comparator I was getting NZEC. Why so? Please help me out!!! here is my code using comparable interface https://www.codechef.com/viewsolution/14641628 here is my code using comparator interface https://www.codechef.com/viewsolution/14641516
Question is Stable Market from April Long challenge

The comparisons in the two solutions are not the same. Here is your solution that gets AC using the Comparator, I have not changed anything other than the compare function.
Helpful tip: Use lambda expressions to reduce the amount of code you need to write for a custom Comparator. Your array can be sorted easily using the code

Arrays.sort(query, (s1, s2) -> {
    int block_size1 = SMarketBC.block_size;
    if(s1.l/block_size1 == s2.l/block_size1)
        return s1.r - s2.r;
    else
        return s1.l/block_size1 - s2.l/block_size1;
});
1 Like

Thanks Alot!! now I got it. Thankyou for the tip also!!!