Back to exercises

Min Stack

Push each value onto the main stack and also onto a min stack whenever it is less than or equal to the current minimum. When popping, remove it from the min stack too if it matches the current minimum.

Coding Exercises Medium O(1)

Min Stack

Push each value onto the main stack and also onto a min stack whenever it is less than or equal to the current minimum. When popping, remove it from the min stack too if it matches the current minimum.

Implement a stack that supports push, pop, top, and get_min in constant time.