Can anybody help me With LOSTMAX problem?

Can we have the input of array size because I can’t see such thing in example problems, If Yes whats wrong with this code :
—> Link to Question : Contest Page | CodeChef
#include
#include
using namespace std;
int main()
{
int t,n,a[60];
//cout<<“Enter testacase Number\n”;
cin>>t;

while(t--)
{
   // cout<<"Enter No of elements\n";
    cin>>n;
    for(int i=0;i<n+1;++i)
        cin>>a[i];
        sort(a,a+n);
        if(a[n]!=n)
            cout<<a[n];
        else
            cout<<a[n-1];


}

}

No your approach is not correct.we have to find such number in array(i prefer arraylist) which itself is equal to the no of total elements(except itself),then we have discard number iteself from array and sort remaining array and find the max.But may be there is more efficient algorithm than this

Just try this on paper, You will get the right answer.
I dont think we need to remove something. Just check this out on paper.

n is not given in input, that was the trick of this problem. You need to take entire line as input becayse we dont know value of n.

If n is given then yup… your logic is correct. But n is not given here… so you have to find n by taking whole line as input, as @vijju123 said.

i means if we remove n from arraylist then sort the remaining elements and after that we can find max.

n is not given thats you have to find n first,read my algorithm again.