Why is my code giving run error?

Please help me in rectifying this error as I am using the same code code as taught by sir.

Hey Divyansh!, you were making one mistake
just make your while condition as while(!s.empty() and a[i]>a[s.top()])
as before accessing top you should check whether s is non empty.

Sir, but inside the while loop both conditions get checked simultaneously, does it matter in what order do we write the condition?

Yes it does matters!
compiler first checks whether s is empty and if it is, it skips conditions ahead as the answer will be 0 (because of AND)

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.