i coded the solution for pumpwat and it gives correct answer for my test cases and the basic test case,
but on submission it get rejected by the compiler .I can’t find any mistake in my method ,please help me with this.
question link-[CodeChef: Practical coding for everyone][1]
//code
#include<iostream>
using namespace std;
int maxe(int ar[],int n,int j)
{
int index,maxa;
maxa=ar[j];
index=j;
for(int i=j;i<n;i++)
{
if(ar[i]>maxa){
maxa=ar[i];index=i;
}
}
return index;
}
int noof(int ar[],int n){
int n1=n,no=0,j=0;
do{
int index= maxe(ar,n1,j);
int mid=n1/2;
if(index<=(mid-1)){
n1=index;no++;
}
else{
j=index+1;no++;
}
}while(n1>0&&j<n1);
return no;
}
int main(){
int n,t;
cin>>t;
while(t--){
cin>>n;
int ar[n];
for(int i=0;i<n;i++)
cin>>ar[i];
cout<<noof(ar,n)<<endl;
}
}