Can someone explain, why this is not working for negetive number cases


#1

int Solution::candy(vector &A) {
sort(A.begin(),A.end());
int sum=1,x=1;
for(int i=1;i<A.size();i++)
{
if(A[i]>A[i-1]) {x++;}
sum=sum+x;
}
return sum;
}


#2

We should not sort the array because a child having rating more than it’s neighbour should have more candies than it’s neighbours.
The question does not say that the child with maximum rating should have maximum candies.