Intuition: Just think of the case where we return “1” and code it.
rest negative and all be managed automatically(or logically) .
BruteForce:(partially Accepted)
int n= A.size();
for(int i=0;i<n;i++)
{
int num =A[i];
int count =0;
for(int j=0;j<n;j++)
{
if(A[j]>num) count++;
}
if(count ==num){
return 1;
}
}
return -1;
Sorting:
int n = A.size();
sort(A.begin(),A.end());
//This will be a single case , So handling it seprately
if(A[n-1]==0) return 1;
int siz = A.size();
for(int i=0;i<n-1;i++)
{
if(A[i] == siz-1 && A[i]!=A[i+1]) return 1;
siz--;
}
return -1;