Back to questionsDSA Visualizers: 388 Coding Questions Min Stack visualizer Learn Min Stack with a step-by-step Stacks & Queues visualizer, JavaScript source code and a worked example. Practice operations and expressions.
INTERACTIVE EXECUTION STUDIOLEARN BY DOING Predict. Execute. Understand. Follow the source code, inspect live state changes, and predict the next operation before revealing it.
1 / 8 Execution step
Prediction modePanel width Reference example · JavaScript
Inspect reference input [
[
"push",
3
],
[
"push",
1
],
[
"push",
2
],
[
"min"
],
[
"pop"
],
[
"pop"
],
[
"min"
]
] Code Visuals
JavaScript reference implementation · highlighted trace statement
1 const solve = (ops,s)=>{
2 let a=[],m=[],o=[];
3 for (let [op,x] of ops){
4 if (op==="push"){
5 a.push(x);
6 m.push(Math.min(x,m.at(-1 )??Infinity))
7 }else if (op==="pop"){
8 a.pop();
9 m.pop()
10 }else o.push(m.at(-1 ));
11 s("Execute "+op,{
12 Stack:a,Minima:m,Output:o
13 })
14 }
15 return o
16 };
Execution canvas Active ChangedSTEP 1 Execute push Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.
Worked example and algorithm walkthrough Topic: Stacks & Queues · Operations and expressions
Follow the computed execution on the reference input. Advance one step at a time, inspect the changing values and compare your prediction with the final output.
Example input [
[
"push",
3
],
[
"push",
1
],
[
"push",
2
],
[
"min"
],
[
"pop"
],
[
"pop"
],
[
"min"
]
] Execution steps Execute push Execute min Execute pop Computed output [
1,
3
] JavaScript reference implementation const solve = (ops,s)=>{
let a=[],m=[],o=[];
for(let [op,x] of ops){
if(op==="push"){
a.push(x);
m.push(Math.min(x,m.at(-1)??Infinity))
}else if(op==="pop"){
a.pop();
m.pop()
}else o.push(m.at(-1));
s("Execute "+op,{
Stack:a,Minima:m,Output:o
})
}
return o
};Continue learning Practice related DSA questions in the same topic.