Here is the code :- https://ide.codingblocks.com/s/466700, please specify what is the error in the code?
MinMaxStack Code Implementation
why is it so? because any point maxStack, minStack and stack would be of same size.
also if we are using maxStack instead then also why we are updating currentmin in it, should not we check separately in similar way for the minStack?
…
look at ur push function, u are pushing in ur stack first.
and then u are updating min and max stack. becuase of that stack size will be 1 greater than min and max size at the time of pushing in stack . thats why replaced the statement.
in the push function ? it is becuase the new element might be next smaller than current minimum, or it might be greater than maximum so far. so it is required to update both.
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.