Find the maximum element in a stack in O(1) (constant time).
Design a stack to get the maximum element from a stack in constant time.
For example:
To understand this problem, let’s take an example. Suppose, the following elements are pushed in a stack.