Easy C++ O(nlogn) time and O(1) space solution


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