I guess that’s not clearing your whole array but clearing only the first element.
And I don’t understand why you are sorting the array. I have changed a little bit your code (actually removed some parts).
This gets AC : https://ideone.com/QkmrSM
Vote if it was helpful.
Try this testcase : 1 1 1
Thanks after seeing the editorial i also got the point that there is no need of sorting the array then i solved the problem by creating frequency map much the same way u r doing…
I was just thinking that my code was giving correct answer for all test cases i tried but still showing wrong answer.
I was not able to figure out problem in my code
my original code is giving right answer for this testcase as well