LeetCode 155 Min Stack - Problem Statement

The problem

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

MinStack(): Initialize the stack.

push(val): Push val onto the stack.

pop(): Remove the top element.

top(): Get the top element.

getMin(): Retrieve the minimum element.

All operations must work in O(1)O(1) time.

Constraints: 231val2311-2^{31} \le val \le 2^{31} - 1. Up to 3×1043 \times 10^4 operations.