Can somebody explain why this is the expected output?

Input: -1 -1 -2 4
Expected output: 6
I thought after sorting the list becomes: -2 -1 -1 4, then there’re [1 2 2 3] candies = 8 candies in total. Why it turns out 6?

i/p = -1 -1 -2 4
o/p= [1 2 1 2] 6 candies.

Click here to start solving coding interview questions