×

# NZEC using comparator but AC using comparable interface

 0 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 asked 23 Jul '17, 01:06 3★kunal12 44●5 accept rate: 0%

 1 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; }); answered 23 Jul '17, 01:31 6★meooow ♦ 7.3k●7●20 accept rate: 48%
 0 Thanks Alot!! now I got it. Thankyou for the tip also!!!! answered 23 Jul '17, 02:10 3★kunal12 44●5 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×124
×10

question asked: 23 Jul '17, 01:06

question was seen: 218 times

last updated: 23 Jul '17, 02:10