Code is working correct if enter only 1 test case at a time

My code is working correct if i am giving only one test case at a time
For 2 test cases It shows incorrect result in one of them
My code is

Hello @Ramitgoel,

The problem is not with number of test cases.
However, you have not handled the case, when there is a increase after decrease, properly.
This is causing a logical error.
Hence, leading to a wrong output.

I have modified your code:

Hope, this would help.
Give a like if you are satisfied.

The new code is not showing a correct ans for the test case
@S18ML0016

hey @Ramitgoel,

I just submitted twice and it is giving correct output

Please, try to submit it once again.
Let me know, if you still face any issue.

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.