Why this code doesn't work?


#1

int Solution::solve(vector &A) {
sort(A.begin(),A.end());

for(int k=0;k<A.size();k++) {
    if(A[k]==A.size()-k-1) {
        if(k+1==A.size()||A[k]!=A[k+1])
        return 1;
    }
    if(A[k]>(A.size()-1-k))
    return -1;
}

}

input : [ -4, -2, 0, -1, -6 ]
expected : 1
observed : -1