Dang! Your program was too slow to compute the answer to one or more testcases. Think - is there a more efficient way to arrive at the solution than brute force?

Dang! Your program was too slow to compute the answer to one or more testcases. Think - is there a more efficient way to arrive at the solution than brute force? help me

@Varun_a19
0. Create inc[n] and dec[n]

  1. Initialize inc[0] to 1 and dec[n-1] to 1
    a. Till end of the array ie, i=1 to n, if arr[i] > arr[i-1] then inc[i] = inc[i-1] + 1. else, inc[i] = 1
    b. From the end of the array ie, i = n-2 till i =0, if arr[i] > arr[i+1] then dec[i] = dec[i +1] +1 else, dec[i] = 1
    then final ans is
for (int i = 1; i < n; i++) 
            if (inc[i] + dec[i] - 1 > max) 
                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.