Workspace Minimum Multiplications To Reach End
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Minimum Multiplications to Reach End visualizer

Learn Minimum Multiplications to Reach End with a step-by-step Graphs visualizer, JavaScript source code and a worked example. Practice topological sorting and shortest paths.

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 / 7Execution step
Reference example · JavaScript
Inspect reference input
{
  "a": [
    2,
    5,
    7
  ],
  "start": 3,
  "end": 30
}

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = ({
a,start,end
},s)=>{
let q=[start],d=new Map([[start,0]]);
while(q.length){
let u=q.shift();
s("Expand multiplications modulo 100000",{
Multipliers:a,Current:[u],Steps:[d.get(u)],Queue:q.slice(0,30)
});
if(u===end)return d.get(u);
for(let x of a){
let v=u*x%100000;
if(!d.has(v)){
d.set(v,d.get(u)+1);
q.push(v)
}
}
}
return -1
};

Execution canvas

Active Changed
STEP 1

Expand multiplications modulo 100000

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

Multipliers3 items
Current1 items
Steps1 items
Queue0 items

Empty at this step.

Keyboard: Space to play · Left / Right to stepExplore next problem

Worked example and algorithm walkthrough

Topic: Graphs · Topological sorting and shortest paths

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,
    5,
    7
  ],
  "start": 3,
  "end": 30
}

Execution steps

  1. Expand multiplications modulo 100000

Computed output

2
JavaScript reference implementation
const solve = ({
  a,start,end
},s)=>{
  let q=[start],d=new Map([[start,0]]);
  while(q.length){
    let u=q.shift();
    s("Expand multiplications modulo 100000",{
      Multipliers:a,Current:[u],Steps:[d.get(u)],Queue:q.slice(0,30)
    });
    if(u===end)return d.get(u);
    for(let x of a){
      let v=u*x%100000;
      if(!d.has(v)){
        d.set(v,d.get(u)+1);
        q.push(v)
      }
    }
  }
  return -1
};

Continue learning

Practice related DSA questions in the same topic.