Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Use one stack for values and a second stack to track current minimum values. Push into the min stack whenever the new value is smaller than or equal to the current minimum. When popping, also pop from min stack if the removed value equals the current minimum.
The min stack stores the minimum value for each state where minimum changes. This keeps current minimum available at the top, so getMin is constant time.
Updated Feb 2026