Workspace Ninja Training
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Ninja Training visualizer

Learn Ninja Training with a step-by-step Dynamic Programming visualizer, JavaScript source code and a worked example. Practice one dimensional dp.

INTERACTIVE EXECUTION STUDIO
LEARN BY DOING

Predict. Execute. Understand.

Follow the source code, inspect live state changes, and predict the next operation before revealing it.

1 / 4Execution step
Reference example · JavaScript
Inspect reference input
[
  [
    10,
    40,
    70
  ],
  [
    20,
    50,
    80
  ],
  [
    30,
    60,
    90
  ]
]

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = (a,s)=>{
let d=[0,0,0];
for(let r of a){
d=r.map((v,j)=>v+Math.max(...d.filter((_,i)=>i!==j)));
s("Choose activity different from previous day",{
Points:a,DP:d
})
}
return Math.max(...d)
};

Execution canvas

Active Changed
STEP 1

Choose activity different from previous day

Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.

Points3 rows
DP3 items
Keyboard: Space to play · Left / Right to stepExplore next problem

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,
    40,
    70
  ],
  [
    20,
    50,
    80
  ],
  [
    30,
    60,
    90
  ]
]

Execution steps

  1. Choose activity different from previous day

Computed output

210
JavaScript reference implementation
const solve = (a,s)=>{
  let d=[0,0,0];
  for(let r of a){
    d=r.map((v,j)=>v+Math.max(...d.filter((_,i)=>i!==j)));
    s("Choose activity different from previous day",{
      Points:a,DP:d
    })
  }
  return Math.max(...d)
};

Continue learning

Practice related DSA questions in the same topic.