[SHUFFLE] Why is this solution incorrect?

Question link : CodeChef: Practical coding for everyone
Solution link : CodeChef: Practical coding for everyone

There can be the case when there are multiple occurrences of the same value which could change in order when you sort them so the answer will be wrong when you compare the absolute difference of shift.
Suppose you have an array like this [3,1,3,4,1,1,1,2] and k = 3, but when you sort you cannot tell which of the ‘1’ will be at first position or second or third or fourth since the sort() function does not work like that.

1 Like

2 2
2 1
answer should be “no”

1 Like

Yeah that is true but for sub task it would pass because there are distinct numbers. I am not able to find mistake for sub task.

@akshayanand729 his test case explains the mistake.

Check your answer for the test case he provided.

You are sorting in decreasing order. So this has not pass even sub task and your sol will be wrong when there are duplicate numbers.