My solution is failing for a large number of negative values


#1

This is my code

int Solution::solve(vector<int> &a) {
    vector<int> count(a.size());
    sort(a.begin(),a.end());
    for(int i=0;i<a.size()-1;i++){
        if(a[i] == a[i+1]) {
            count[i] = a.size()-i;
        }
        else{
            count[i] = a.size() - i - 1;
        }
    }
    count[a.size()-1] = 0;
    for(int i = 0;i<count.size();i++){
        if(a[i] == count[i]){
            return 1;
        }
    }
    
    return -1;
}