Get minimum element from stack in O(1).
In this problem, we have to design a stack that supports push, pop, top, and retrieving the minimum element in constant time (O(1)).
push(x) — Push element x onto stack.
pop() — Removes the element on top of the stack.
top() — Get the top element.
getMin() — Retrieve the minimum element in the stack.
For example: Suppose, If we push the following elements in a stack.
9 ==> Top
1
2
3
Then if we call getMin() method, It should return 1 in O(1) (constant time).