Implement a stack that is able to return the maximum of the stack at any moment. All operations must be O(1), or amortized O(1) on the push operation.
The Idea:
We maintain a secondary stack, that which we will call MaxStack. It is a special kind of stack, so it should have very similar methods, with a few exceptions.
We will encapsulate a regular stack, that will be used to maintain the MaxStack ordinary operators like push, pop, top.
MaxStack will interface with another stack we will call max_s that overwrites a few operators.
push will add the new integer to max stack iff it exceeds the current size of its current max. This has the effect of maintaining a history of the max elements pushed in.
So when we pop we will naturally obtain the previous max element that will always be inline with the ordinary stack, since we pop from both containers.