We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
If you dont keep the arguments, then it wont work. Consider step (3) and then step (2) i.e. delete element at the top and then print the maximum of the stack.
With you approach, if the top of the stack contains 'current' maximum element, how will you perform step (2) which has to find the new maximum value (since the old maximum has been deleted by the prior operation).
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Element
You are viewing a single comment's thread. Return to all comments →
If you dont keep the arguments, then it wont work. Consider step (3) and then step (2) i.e. delete element at the top and then print the maximum of the stack.
With you approach, if the top of the stack contains 'current' maximum element, how will you perform step (2) which has to find the new maximum value (since the old maximum has been deleted by the prior operation).