Simple and intuitive approach in c++


#1

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