Back to questionsDSA Visualizers: 388 Coding Questions Minimum Falling Path Sum visualizer Learn Minimum Falling Path Sum with a step-by-step Dynamic Programming visualizer, JavaScript source code and a worked example. Practice grid dp.
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 / 7 Execution step
Prediction modePanel width Reference example · JavaScript
Inspect reference input {
"a": [
[
2,
1,
3
],
[
6,
5,
4
],
[
7,
8,
9
]
],
"triangle": false
} Code Visuals
JavaScript reference implementation · highlighted trace statement
1 const solve = ({
2 a,triangle
3 },s)=>{
4 let d=a.map(r=>r.slice());
5 for (let i=a.length-2 ;
6 i>=0 ;
7 i--)for (let j=0 ;
8 j<a[i].length;
9 j++){
10 let candidates=triangle?[d[i+1 ][j],d[i+1 ][j+1 ]]:[d[i+1 ][j-1 ],d[i+1 ][j],d[i+1 ][j+1 ]];
11 d[i][j]=a[i][j]+Math.min(...candidates.filter(x=>x!==undefined));
12 s("Choose cheapest next cell",{
13 Grid:a,DP:d,Cell:[i,j]
14 })
15 }
16 return triangle?d[0 ][0 ]:Math.min(...d[0 ])
17 };
Execution canvas Active ChangedSTEP 1 Choose cheapest next cell Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.
Worked example and algorithm walkthrough Topic: Dynamic Programming · Grid DP
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 {
"a": [
[
2,
1,
3
],
[
6,
5,
4
],
[
7,
8,
9
]
],
"triangle": false
} Execution steps Choose cheapest next cell Computed output 13 JavaScript reference implementation const solve = ({
a,triangle
},s)=>{
let d=a.map(r=>r.slice());
for(let i=a.length-2;
i>=0;
i--)for(let j=0;
j<a[i].length;
j++){
let candidates=triangle?[d[i+1][j],d[i+1][j+1]]:[d[i+1][j-1],d[i+1][j],d[i+1][j+1]];
d[i][j]=a[i][j]+Math.min(...candidates.filter(x=>x!==undefined));
s("Choose cheapest next cell",{
Grid:a,DP:d,Cell:[i,j]
})
}
return triangle?d[0][0]:Math.min(...d[0])
};Continue learning Practice related DSA questions in the same topic.