Wrong Answer on a case


#1

I was getting 1 for the input but expected says its -1 but if we solve by hand it should be 1
Input:
184 -4 7 5 3 5 -4 2 -1 -9 -8 -3 0 9 -7 -4 -10 -4 2 6 1 -2 -3 -1 -8 0 -8 -7 -3 5 -1 -8 -8 8 -1 -3 3 6 1 -8 -1 3 -9 9 -6 7 8 -6 5 0 3 -4 1 -10 6 3 -8 0 6 -9 -5 -5 -6 -3 6 -5 -4 -1 3 7 -6 5 -8 -5 4 -3 4 -6 -7 0 -3 -2 6 8 -2 -6 -7 1 4 9 2 -10 6 -2 9 2 -4 -4 4 9 5 0 4 8 -3 -9 7 -8 7 2 2 6 -9 -10 -4 -9 -5 -1 -6 9 -10 -1 1 7 7 1 -9 5 -1 -3 -3 6 7 3 -4 -5 -4 -7 9 -6 -2 1 2 -1 -7 9 0 -2 -2 5 -10 -1 6 -7 8 -5 -4 1 -9 5 9 -2 -6 -2 -9 0 3 -10 4 -6 -6 4 -3 6 -7 1 -3 -5 9 6 2 1 7 -2 5


#2

Nigga you are forgetting the fact that the intergers in front of it shoud be greater. It can’t even be equal. Make sure to include the condition of the integer not equal to the one in front of it.


#3

I too had the same problem. Rectified it using upper_bound as the array is sorted.

int Solution::solve(vector &A) {
if(A.size()==1 && A[0]!=0)
return -1;
if(A.size()==1 && A[0]==0)
return 1;
sort(A.begin(),A.end());

int numbers;
for(int i=0;i<A.size();i++){
    auto upper = upper_bound(A.begin(),A.end(),A[i]);
    numbers = A.size()-(upper-A.begin());
    if(A[i]==numbers)
        return 1;
    
}
return -1;

}