Developer

This experience deserves a bigger screen

The DSA Visualizer is designed for deep focus,
side-by-side code, and real-time execution insight.

On small screens, that level of clarity can't be preserved.

Open on a tablet (landscape) or desktop for the intended experience.

Desktop experience preview

Min StackStep-by-Step Visualization

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

Problem Statement

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

Approach

We maintain two stacks: a main stack for the actual values and a "min stack" that tracks the minimum value at each level. When pushing a value, we push it to the main stack and push the new minimum (min of current value and current top of min stack) to the min stack.

Time & Space Complexity

Time complexity is O(1) for all operations (push, pop, top, getMin). Space complexity is O(n) to store the auxiliary min stack.

Interactive Visualization

Loading Interactive Visualizer...

Click "Play" or use arrow keys to step through the execution.