Junior — Senior
Stack capable of quickly returning the minimum element
livecode
Task condition
It is necessary to create a stack structure that supports four operations:
- push(x) — add element x to the stack;
- pop() — remove the element at the top of the stack;
- top() — return the value of the top element without removing it;
- get_min() — get the current smallest element among all in the stack. All listed operations must work in constant time O(1).