Maximum length bi-tonic subarray

#include
using namespace std;
int main(){
int n;
cin>>n;
for(int j=0;j<n;j++){
int a[100];
int x;
cin>>x;
for(int i=0;i<x;i++){
cin>>a[i];
}
int inc[100];
inc[0]=1;
for(int i=1;i<x;i++){
if(a[i]>a[i-1]){
inc[i]=inc[i-1]+1;
}
else
inc[i]=1;
}

int dec[100];
dec[x-1]=1;
for(int i=x-2;i>=0;i–){
if(a[i]>a[i+1]){
dec[i]=dec[i+1]+1;
}
else
dec[i]=1;
}

int max=inc[0]+dec[0]-1;
for(int i=0;i<x;i++){
if(inc[i]+dec[i]-1>max){
max=inc[i]+dec[i]-1;
}}
cout<<max<<endl;}}
y this code is showing error?

@tishya_goyal
hello tisha

it should be >=

similarly here

also check maximum value of n and declare ur array size bigger than that

1 Like

its time complexity is very high…can we use any other approach?

@tishya_goyal
tishya this is the best approach ,
to pass all test cases add these two line in the start of main function
ios_base::sync_with_stdio(false);
cin.tie(NULL);

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like