In this problem , i thought of a logic but it was O(N^2), which obviously resulted into TLE. Can anyone explain a faster way? asked 30 Sep '12, 09:39

The problem could be reduced to sorting the array by some trivial position tricks. EDIT: answered 30 Sep '12, 09:54
I know the "inversion count method", the thing i was asking for that "trivial position tricks", could you explain a bit more about that.
(30 Sep '12, 10:00)
@slash_it Edited my answer to make it more lucid
(30 Sep '12, 10:43)

Well, I did the same and it was giving correct answer for all the testcases that were given and even I checked for upto 20 numbers and it was giving me the correct answer but my submission showed the incorrect answer and I dont know why it is showing incorrect.Here is my code:
link
This answer is marked "community wiki".
answered 30 Sep '12, 10:50
