Maximum Length Biotonic Subarray

Hello sir/ Ma’am, my code is only passing one test case, could you please tell me what’s wrong? https://ide.codingblocks.com/s/231792

@priyanshi.agarwal3405
It is not necessary that the sequence will start from the first index only which is what you have assumed in the code I believe
Have a look at this https://www.geeksforgeeks.org/maximum-length-bitonic-subarray/

Yes sir, i have taken that into account, for that purpose only i have put the check in line 10-18. Please see. Also gfg link which you shared is using a different approach and i have used a diff one. It would be great if you could tell me what’s wrong in my code or my logic.

@priyanshi.agarwal3405
Your logic is not correct at all unfortunately
There is nothing right about it so that I can point out the mistake
You can see similar correct logic here https://www.geeksforgeeks.org/maximum-length-bitonic-subarray-set-2-time-o1-space/

Sir can you please elaborate why my approach is not correct at all? I have used the peak and valley approach i.e. the approach that we usually use for buy and sell stocks problem.
Also it would be great if you can share any test case where my approach fails, that would help me to understand the logic where i am getting wrong.

Hey @priyanshi.agarwal3405
Thanks for explaining your approach
I didn’t understand it properly I believe

The issue is that due to use of <= >= etc there may be plateaus instead of valleys where your code doesn’t start new range

You can understand better with this test case

47
24 34 35 36 39 42 43 50 53 66 66 70 79 82 85 91 97 69 3 3 4 7 8 15 23 23 32 32 32 32 35 40 41 41 48 54 55 57 59 61 72 75 83 88 96 97 99

Made the changes, still only one test case is passing.

@priyanshi.agarwal3405
Now your code wont work since you are not handling equality cases
So I recommend you to once go through the link I sent you