Design a stack-like data structure that supports the following operations, each in O(1) time:
push(x)
: push integer
x
onto the stack
pop()
: remove the top element (assume it’s non-empty when called)
top()
: return the top element
getMin()
: return the minimum value currently in the stack
getMin()
is called on an empty stack? (Specify an approach: error/exception/sentinel.)