Can you explain this part of code given in editorial?

Step 3) Find the length of maximum length bitonic sequence
max = inc[0] + dec[0] - 1;
for (i = 1; i < n; i++)
if (inc[i] + dec[i] - 1 > max)
max = inc[i] + dec[i] - 1;

max = inc[0] + dec[0] - 1;//What are we calculating in this step?

Hey @isingh
We are not calculating anything there ,we are just setting it for reference to other values u can start with max =0 and traverse the whole array from 0 to n-1

If you are making the meaning of Inc(i)+dec(i) -1
then inc(i) has the length of max increasing array till ith index and dec(i) has the length of max decreasing array from ith index
so we take sum of both which gives us bitonic subarray and -1 is because ith element is included in both

Eg
1 6 8 9 3 4 6 5
inc array
1 2 3 4 1 2 3 1
dec array
1 1 1 2 1 1 1 2
max(1+1-1,2+1-1,3+1-1,…)
Ans 4 + 2 -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.