Back to questionsDSA Visualizers: 388 Coding Questions Maximal Rectangle visualizer Learn Maximal Rectangle with a step-by-step Stacks & Queues visualizer, JavaScript source code and a worked example. Practice monotonic structures.
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 / 21 Execution step
Prediction modePanel width Reference example · JavaScript
Inspect reference input [
[
1,
0,
1,
0,
0
],
[
1,
0,
1,
1,
1
],
[
1,
1,
1,
1,
1
],
[
1,
0,
0,
1,
0
]
] Code Visuals
JavaScript reference implementation · highlighted trace statement
1 const solve = (a,s)=>{
2 let h=Array(a[0 ].length).fill(0 ),b=0 ;
3 for (let row of a){
4 h=h.map((v,i)=>row[i]?v+1 :0 );
5 let st=[];
6 for (let i=0 ;
7 i<=h.length;
8 i++){
9 while (st.length&&(i===h.length||h[st.at(-1 )]>h[i])){
10 let j=st.pop();
11 b=Math.max(b,h[j]*(i-(st.at(-1 )??-1 )-1 ));
12 s("Evaluate histogram rectangle",{
13 Matrix:a,Heights:h,Stack:st,Best:[b]
14 })
15 }
16 if (i<h.length)st.push(i)
17 }
18 }
19 return b
20 };
Execution canvas Active ChangedSTEP 1 Evaluate histogram rectangle 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 · Monotonic structures
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 [
[
1,
0,
1,
0,
0
],
[
1,
0,
1,
1,
1
],
[
1,
1,
1,
1,
1
],
[
1,
0,
0,
1,
0
]
] Execution steps Evaluate histogram rectangle Computed output 6 JavaScript reference implementation const solve = (a,s)=>{
let h=Array(a[0].length).fill(0),b=0;
for(let row of a){
h=h.map((v,i)=>row[i]?v+1:0);
let st=[];
for(let i=0;
i<=h.length;
i++){
while(st.length&&(i===h.length||h[st.at(-1)]>h[i])){
let j=st.pop();
b=Math.max(b,h[j]*(i-(st.at(-1)??-1)-1));
s("Evaluate histogram rectangle",{
Matrix:a,Heights:h,Stack:st,Best:[b]
})
}
if(i<h.length)st.push(i)
}
}
return b
};Continue learning Practice related DSA questions in the same topic.