Maximum length bitonic subarray

#include<bits/stdc++.h>
using namespace std;
int find(int n, int a[])
{
int inc=0,dec=0,max=0,curr=0;
if(n==1)
return 1;
for(int i=1;i<n;i++)
{
if(a[i]>=a[i-1])
{ if(inc==0)
{ inc=inc+2;
if(dec!=0)
{
dec=0;
}
}
else{
if(dec!=0)
{
inc=2;
}
else
{inc=inc+1;}

		}
		
		if(inc>=max)
		{
          max=inc;
		}
	}
	else
	{
		if(dec==0)
		{   if(inc==0)
		   {
			dec=dec+2;
			if(dec>max)
			{max=dec;}}
			else{
				dec=dec+1;
				curr=dec+inc;
				if(curr>max)
				{max=curr;}
			}
			
		}
		else{
			if(inc==0)
			{
				dec=dec+1;
				if(dec>max)
				{max=dec;}
				
			}
			else
			{
				dec=dec+1;
				curr=inc+dec;
				if(curr>max)
				{max=curr;}
			}
			
		}
		

	}


}
return max;

}
int main() {
int n,t,a[1000000];
cin>>t;

for(int i=0;i<t;i++)
{int max=0;
cin>>n;
for(int j=0;j<n;j++)
{
	cin>>a[j];

}
max=find(n,a);
cout<<max<<endl;

}
return 0;

}
this s my code, it runs correctly for many sample testcases, but fail all test cases.

@shashank3256
for bigger test cases like
100
79 6 62 23 206 45 48 379 233 409 386 17 413 368 321 466 197 154 193 325 349 57 295 68 176 267 487 90 131 186 99 247 263 21 109 11 258 450 425 451 371 406 250 334 230 257 490 84 181 464 156 20 27 198 241 105 400 269 127 132 151 282 24 238 392 80 345 445 252 396 217 359 462 125 353 297 458 196 378 19 130 52 424 338 275 426 141 346 268 232 41 72 189 213 422 66 397 222 287 77
you get
45 while the ans is 6

1 Like

I didnt take that into account!