My ocde is giving wrong output, Kindly check

Custom I/p= 5 , 30 35 40 38 35 Desired Output= 1 2 3 1 1 END My output = 0 1 2 1 1 END

@7nishit,

  • Line 17: li betterDay=s.empty()? 0 : s.top();
  • Correction: li betterDay=s.empty()? -1 : s.top();

Also you are declaring very large arrays, declare them globally.

It worked by changing li betterDay=s.empty()? 0 : s.top(); to li betterDay=s.empty()? -1 : s.top(); but can you please explain the reason for this

@7nishit,
Just dry run on the test case you provided above. No reason, it’s just that sentinel value is shifting the answer.

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.