Could there be a better way to solve the "Buying sweets" problem.

I solved this but I am not sure the approach I used is appropriate or not, or there could be any better way to solve this question.

This is my solution, you can see what I did.

I solved the problem by sorting the array and checking if neglecting the smallest element will change the no of sweets i can buy or not.Your solution is better as it has time complexity of O(n).