Ar timestamp 11:24

i dont understand how sir calculated 3rd step ?

It’s normal mathematics, say your cur_min is y and lets assume it is at current top, so when you pop, your cur_min is popped and cur_min should be updated to next smaller element present in stack, you can find it by doing this:
cur_min(updated) = 2cur_min - stack.top()
this is valid because let x be that next smaller element in stack, so while pushing , stack.top() = 2
y-x, also cur_min = y
so cur_min(updated) = 2y - (2y-x) = x.

1 Like

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.

1 Like