Maximum length bitonic subarray

how to write in constant space ?

Hey Dhairya, to solve this question in O(1), we should first try to find the increasing subarray, suppose biggest element occurs i, now find the decreasing subarray from a[i], as soon as the subarray starts increasing stop, and check if the accumulated sum is better or not, if it is better update answer. Now again continue the same procedure from the element we last left.
eg
1 2 3 2 5 6 7 1.
first increasing subarray 1 2 3 now it decreasing subarray 3 2 (total sum =8).
beginning where we left increasing sub array 2 5 6 7 now decreasing sub array 7 1 (total sum= 21)
ans 21

what’s the point of accumulated sum, here we just have to find the maximum length subarray which satisfies the given condition

for ex array is, 1 2 3 1 2 1 1 1 , then first subarray 1 2 3 1 acc sum=7, and second subarray 1 2 1 1 1 acc sum =6, then answer would be 1 2 1 1 1 of length=5

My mistake, I made a mistake while reading the question (read it as max sum bitonic subarray). The question asks for anly length so we need not to calculate sum, instead we should keep track of length.

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.