This problem was asked by Amazon.
Implement a stack API using only a heap. A stack implements the following methods:
push(item)
, which adds an element to the stackpop()
, which removes and returns the most recently added element (or throws an error if there is nothing on the stack)
Recall that a heap has the following operations:
push(item)
, which adds a new key to the heappop()
, which removes and returns the max value of the heap