Why this solution does not work


#1

Can any ony please say why this does not work for [-6,-4,0,-2,-1]
int Solution::solve(vector &A) {
sort(A.begin(), A.end());
int i, n = A.size();
int k;
for(i=0;i<n;i++){
// cout<<A[i]<<" ";
while(i<n-1 && A[i]==A[i+1]){
i++;
}
k=n-(i+1);
if(A[i] == k)
return 1;
}
return -1;
}`