Other than brute force approach

whats other way to solve this question im thinking of that only

its max length biotonic subarray

@sktg99 Follow this approach:
Consider the given array arr={12,4,78,90,45,23}

  • Construct an array increasing[] such that increasing[i] will contain the length of non decreasing subarray ending at arr[i] from LEFT TO RIGHT manner. Therefore for the given array increasing[]={1,1,2,3,1,1}
  • Construct another array decreasing[] from RIGHT TO LEFT manner of the given array such that decreasing[i] contains length of non-decreasing subarray starting at arr[i].Note that this is non-decreasing from backward direction or in RIGHT to LEFT manner…so it will actually be decreasing as seen from LEFT to RIGHT manner. So decreasing[]={2,1,1,3,2,1}
  • Start iterating the increasing[] and decreasing[] array. The maximum of (increasing[i]+decreasing[i]-1) will be the maximum length of biotonic subarray. Here it is 5 for i=3.

Hope this helps.