I ran the code given below on Ideone and on Xcode (an IDE on mac). Shockingly, they gave me two different answers for the test cases given along with the problem.
@dhruvmullick i executed your code in my Linux machine and it showed the same output as given in the test case…so i’think there is some other problem in your code …
@raj01104 Okay but that still doesn’t explain the different outputs. I’ve had another weird result when I try to print the inputs after sorting.
Ideone shows the correct result, but my IDE shows something else
On a quick look I found these issues in your code:
Line 41: sort(player,0,n,temp); - I believe it should be sort(player,0,n-1,temp); instead.
Line 134: sort(player, imid, iend, temp); - Element at imid position has already been sorted in line 133. Why sort it again? It should be sort(player, imid+1, iend, temp); instead.
The discrepancy you are talking about is most probably due to processing of garbage values I pointed out above. In addition to it, your algorithm will give unexpected results if you execute it for N=1 case. I will leave it to you to figure out why.
An advice - declare your bigger arrays global or there is a great chance that you will get TLE. Again, I will leave it to you to figure out why