Inversion Count problem

I am not able to understand what’s the problem with my code and why it is giving wrong answer in all cases. Although, my code is giving correct answer for the sample test case given in the question itself. Here is my code: https://ide.codingblocks.com/s/236988

@a_krisna22 this a recursive code, we need maintained temp, so pass temp to merge and merge sort
Same temp, do not create it again and again
Also as this is recursive k=s, not 0 always.
Also do a bit dry run you will find that if condition in merge is bit off
if should be
i<=mid-1
If this resolves your doubt mark it as resolved.

I already kept k=s, and “merge” function is not recursive, “merge sort” is recursive and I totally followed the code shown in tutorial. I only change int to long long int

now its working , I only changed the temp to array copy loop . Changed it to " i<=e " from “i<e”. and it works fine

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.