Min Stack

Medium
StackDesignAmazonBloomberg
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Process a sequence of operations and print the results of the query operations. Input format: - First line: q - Next q lines: one operation each, one of: - `push x` — push integer x - `pop` — remove the top element - `top` — print the top element - `getMin` — print the current minimum `pop`, `top`, and `getMin` are only issued when the stack is non-empty. Print one line per `top` or `getMin` operation, in order.

Constraints

1 <= q <= 10^5
-10^9 <= x <= 10^9

Sample tests

Sample 1

Sample 2

Sign in to submit