will yo please explain your code
Doesn't got a single thing
Hey @ashish_arora369
We are making 2 array, one inc, that will have at ith position,the length of the increasing subarray till i, similary a dec array that will have length of decreasing subarray till ith (ith till n).
For inc array compute this length from left to right
For dec array compute this length from right to left.
Now for every i you have both increasing length till that point and decreasing length to get answer you will bemaximizing(inc[i]+dec]i]-1) here -1 because a[i] is counted in both inc[i] & dec[i]
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
but why we use 1 in inc[0] and dec[n-1]
because inc[0] means increasing subarray till 0th index(including it) and we have some nome on arr[0] so only considering it the length of increasing subarray till 0 becomes 1
Same goes for dec[n-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.