Min Stack

Design a stack that supports push(x), pop(), top(), and retrieving the minimum element in constant time. Implement the MinStack class.

Input Format

nums = elements of stack (last element is top)

Output Format

minimum element in the stack

Constraints

Examples

Example 1:

Input:

nums = [3,1,4,2]

Output:

1

Explanation:

The minimum element is 1.

Example 2:

Input:

nums = [5,5,5]

Output:

5

Explanation:

All elements are equal; min is 5.

Loading...
Min Stack - Stack DSA Problem