Maximum length Bitonic Array

I was able to solve using two loops but two test cases didn’t passed so I tried to optimize but last three test cases are not passing what is wrong with my code please tell the correction.

hi @himanshuanand729 try solving this problem in gfg as the test cases in coding blocks is having issues in last 2 test cases

could you please help what I am doing wrong minor mistake that by optimized method test case 2 is not passing.
Please point out the mistake if possible as it was passed in method having multiple loops submission that I made.

hi @himanshuanand729 send the code on ide.codingblocks.com

I have sent the code on the given link.

Have u rectified the error , please tell my mistake in the code. @talhashamim001

hi @himanshuanand729 please save and send the code in the chat here, havent got any link yet here

#include
#include
using namespace std;

int decr(int A[],int n)
{
int mxsum=1;
int cnt=1;
for(int i=1;i<n;i++)
{
if(A[i]>=A[i-1])
{
mxsum=max(cnt,mxsum);
cnt=1;
}
else {
cnt++;
}
}
mxsum=max(cnt,mxsum);
return mxsum;
}

int incr(int A[],int n)
{
int i,mxsum=1;
int cnt=1;
for(i=1;i<n;i++)
{
if(A[i]>=A[i-1])
{
cnt++;
}
else
{
mxsum=max(cnt,mxsum);
cnt=1;
}
}

mxsum=max(cnt,mxsum);
return mxsum;
}
int incrdecr(int A[],int n)
{
int mxsum=1;
int cnt=1,flag=0;
for(int i=1;i<n;i++)
{
if(flag==0)
{
if(A[i]>=A[i-1])
{
cnt++;
}
else
{
flag=1;
}
}

   if(flag==1)
   {
       if(A[i]<A[i-1])
       {
        cnt++;
       }
       else
       {
        mxsum=max(cnt,mxsum);
	   cnt=2;
	   flag=0;
       }
   }

}
mxsum=max(cnt,mxsum);
return mxsum;
}

int main()
{
int t,n,i,j;

cin>>t;

for(i=0;i<t;i++)
{
cin>>n;
int* A = new int[1000000];

for(j=0;j<n;j++)
{
 cin>>A[j];
}

int a=incr(A,n);
int b=decr(A,n);
int c=incrdecr(A,n);

cout<<max(a,max(b,c));
cout<<"\n";
}
return 0;
}

iostream and algorithm header file i have included in original code here it is not showing when i am copy pasting.

Her other things are also not readable please share the code on online ide
Write save and copy the url and share


Here is the link please look

hi @himanshuanand729 buddy refer

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.