Skip to content
C

Min Stack

Mediumjavapythonccppjavascript

Design a stack that supports push, pop, top and getMin (retrieving the minimum value), all in constant time.

Input Format

The first line contains an integer Q. Each of the next Q lines is one of: push X, pop, top, getMin.

Output Format

For each pop print the removed element (or -1 if empty). For each top print the top element (or -1). For each getMin print the current minimum (or -1 if empty). One value per line.

Input (stdin)

Output

Run your code to see output here...