SPOJ INVCNT Help in logic

I can’t seem to get the correct output for my inversion count code.
Here’s my code:

Refer this article. Here is good explanation. First try to debug your code by yourself by taking reference from here.

I read it, That is where I got the idea. The inversion count code given there is complex

Hey @aniketsanadhya, you missed a return 0; outside the if(start < end) block of the mergesort function. As a result your mergesort function was returning garbage values when start==end. Hope this helps!


@meow is right, here is what the hackerrank compiler gave me-

solution.cc:46:5: error: control reaches end of non-void function [-Werror=return-type]

So, after correcting your code there, I tested it on ~20 test cases (all small though) and your program is handling them quite well. I think you should try submitting after adding a return 0 there, I think your code will get accepted.

(Note- Cant guarantee about TLEs tho, I tested on small input.)

1 Like