Maximum length bitonic subarray

Kindly help me with this, my code looks all fine but doesn’t run well

@Enigmatctrance
Hello Tanishq,
please share ur code.

#include<bits/stdc++.h> using namespace std; int bito(int a[], int n){ if(n==0) return 0; if(n==1) return 1; int start=0, i=0,ma,j, r=0; while(i<n-1){ ma=1; for(i=start;i<n-1;i++){ if(a[i]<=a[i+1]){ ma++; }//cout<<a[i]<<"\t"<<ma<<"\t"<<i<<endl;} else break; } for(j=i;j<n-1;j++){ if(a[j]>=a[j+1]){ ma++; // cout<<a[i]<<"\t"<<ma<<"\t"<<j<<endl; } else break;} r=max(ma,r); if(n-j>r){ start=j; } else break; } return r; } int main(){ int t; cin>>t; int n; while(t–){ cin>>n; int a[n],e; for(int i=0;i<n;i++) cin>>a[i]; e=bito(a,n); cout<<e<<endl; } }

@Enigmatctrance
follow this step
a) paste ur code here https://ide.codingblocks.com/
b) press save button
c) share the generated link here

@Enigmatctrance
looking into it

@Enigmatctrance
Hello Tanishq,
I think the issue is with coding blocks online judge .because even correct solution is showing wa.
your code looks correct even I manually veriefied on some of the test cases and your code is generating correct output.
Please try again after sometime.

@Enigmatctrance
Hello tanish,
your solution is giving tle for some cases .i would suggest to solve this problem using an important technique( u can use this technique to solve other problem as well)
technique is as follows:
we will maintain two array lets say dec and inc .
value at ith index of inc array will tell the longest increasing subarray ending at ith index.
value at ith index of dec array will tell u longest decreasing subbarray starting from ith index.
Now after constructing these two array we can answer this problem easily
we will iterate from i=0 to i=n-1 and store maximum value of inc[i]+dec[i]-1
I hope u find this helpful

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.

can you tell what type of test case my code is not passing