Solved it using map easy implementation


#1

int Solution::solve(vector &A) {
sort(A.begin(),A.end());
map<int,int> m,q;
for(int i=0;i<A.size();i++){
m[A[i]]++;
}
int p=0;
for(auto i:m) {p+=i.second; q[i.first]=p;}
for(auto i:q){
if(i.first>=0 && i.first==A.size()-i.second) return 1;
}
return -1;
}