We should consider the repetition


#1

we will first sort the vector
sort(A.begin(),A.end());
then we will run a loop
for(int i =0;i<A.size();i++)

consider the repetition
while(i +1<A.size() and A[i]==A[i+1]
{
i++;
}
now work on real situation
if(A[i]== A.size()-1-i)
return 1;

then if we come out of loop
return -1;


#2

Thank you so much explaining the code :slightly_smiling_face: