The editorial for this problem is in java

the editorial for this problem is in java please help me i am not able to develop a approach for the problem.

@Varun_a19 make two arrays inc[ ] and dec[ ] denoting maximum increasing subarray length ending at ith position and maximum decreasing subarray length starting at ith position. So this way if element at ith position is chosen as peak element for bitonic subarray and length of this is inc[i]+dec[i]-1;
So do this:

  1. inc[0]=1, for(i : 1 to n-1) if(a[i]>=a[i-1]) then a[i]=1+a[i-1] else a[i]=1
  2. dec[n-1]=1 , for(i : n-2 to 0) if(a[i]<=a[i+1]) then a[i]=1+a[i+1] else a[i]=1;
  3. for( i: 0 to n-1) ans = max(inc[i]+dec[i]-1)

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.