Why does this not pass all the test cases?


Below is my code, which stands correct for ‘Test’. But when submitted, stands incorrect for 1 test case.
Please help.

int Solution::solve(vector<int> &A) {
int n=A.size();
 sort(A.begin(), A.end());
for(int i=0;i<A.size();i++)
    return 1;
return -1;



consider the case [0, 1, 2, 2, 2]


Ohhh. Right, thank you so much!
That surely was a dumb mistake on my end


Haha, I too had the same doubt, thanks for this.


you are not taking in consideration about duplicate
try for(int j=I;j<size;i++) if(A[j]>i) then use j instead of I in if condition