Back to questionsDSA Visualizers: 388 Coding Questions Frog Jump visualizer Learn Frog Jump with a step-by-step Dynamic Programming visualizer, JavaScript source code and a worked example. Practice one dimensional 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 / 4 Execution step
Prediction modePanel width Reference example · JavaScript
Inspect reference input [
10,
20,
30,
10
] Code Visuals
JavaScript reference implementation · highlighted trace statement
1 const solve = (a,s)=>{
2 let d=[0 ];
3 for (let i=1 ;
4 i<a.length;
5 i++){
6 d[i]=Math.min(d[i-1 ]+Math.abs(a[i]-a[i-1 ]),i>1 ?d[i-2 ]+Math.abs(a[i]-a[i-2 ]):Infinity);
7 s("Choose cheaper predecessor",{
8 Heights:a,DP:d
9 },[i])
10 }
11 return d.at(-1 )
12 };
Execution canvas Active ChangedSTEP 1 Choose cheaper predecessor 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 · One dimensional 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 [
10,
20,
30,
10
] Execution steps Choose cheaper predecessor Computed output 20 JavaScript reference implementation const solve = (a,s)=>{
let d=[0];
for(let i=1;
i<a.length;
i++){
d[i]=Math.min(d[i-1]+Math.abs(a[i]-a[i-1]),i>1?d[i-2]+Math.abs(a[i]-a[i-2]):Infinity);
s("Choose cheaper predecessor",{
Heights:a,DP:d
},[i])
}
return d.at(-1)
};Continue learning Practice related DSA questions in the same topic.