plz help me to solve this problem
Sir i dont get logic
Hello @rakesh800650,
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.
Hope, this would help.
Give a like if you are satisfied.
Sir I got this but I am unable to find logic behind this
Hello @rakesh800650,
In this questions you have to find bitonic sub-arrays.
and then print the size of the largest subarray that is bitonic.
Bitonic sequences are:
- first increasing then decreasing
- entirely increasing
- entirely decreasing.
So, you are computing the count of elements that are increasing continuously upto an index.
And same is done for computing decreasing count. For this we are computing increase from opposite direction i.e. right to left.
Then, we are computing lengths of bitonic sub-array at each index. The current index will act as the point where the pattern changes.
DESCRIPTION:
for 1. __inc. ______ a ______dec. __
for 2. __inc. ______a
for 3. a______dec. __
So, current index will act as point a.
Hope, this would help.
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.