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


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


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.