You are not logged in. Please login at to post your questions!


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 here is my code using comparator interface Question is Stable Market from April Long challenge

asked 23 Jul '17, 01:06

kunal12's gravatar image

accept rate: 0%

edited 23 Jul '17, 01:12

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;
        return s1.l/block_size1 - s2.l/block_size1;


answered 23 Jul '17, 01:31

meooow's gravatar image

6★meooow ♦
accept rate: 48%

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


answered 23 Jul '17, 02:10

kunal12's gravatar image

accept rate: 0%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 23 Jul '17, 01:06

question was seen: 223 times

last updated: 23 Jul '17, 02:10