This is my CPP solution.
class Solution {
public:
int specialArray(vector<int>& v) {
int n = v.size();
if(n==0)
return 0;
vector<int> arr;
sort(v.begin(), v.end());
for(int i = 0; i <= n; i++) {
int lb = lower_bound(v.begin(), v.end(), i) - v.begin();
if(n-lb == i) {
return i;
}
}
return -1;
}
};