Testcase not passing. Check my code.
Maximum length Biotonic subarray
@dbhavanishankar89 You logic may be wrong. It is not giving correct answer for the sample input.
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}
3.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.
No…its giving correct output for above example…please run the code and check once.
For test case:
2
6
12 4 78 90 45 23
4
40 30 20 10
Your output:
5
5
Expected Output:
5
4
Follow the approach as i have said earlier. If you are not able to implement then do let me know.