Back to questionsDSA Visualizers: 388 Coding Questions Word Ladder II visualizer Learn Word Ladder II with a step-by-step Graphs visualizer, JavaScript source code and a worked example. Practice traversal and connectivity.
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 / 6 Execution step
Prediction modePanel width Reference example · JavaScript
Inspect reference input {
"start": "hit",
"end": "cog",
"words": [
"hot",
"dot",
"dog",
"lot",
"log",
"cog"
],
"all": true
} Code Visuals
JavaScript reference implementation · highlighted trace statement
1 const solve = ({
2 start,end,words,all
3 },s)=>{
4 let remaining=new Set(words),q=[[start]],o=[];
5 while (q.length){
6 let next=[],used=new Set;
7 for (let p of q){
8 let u=p.at(-1 );
9 if (u===end)o.push(p);
10 else for (let v of remaining)if ([...u].filter((x,i)=>x!==v[i]).length===1 ){
11 next.push(p.concat(v));
12 used.add(v)
13 }
14 }
15 s("Expand shortest transformation paths",{
16 Paths:q,Next:next,Solutions:o
17 });
18 if (o.length)return all?o:o[0 ].length;
19 for (let v of used)remaining.delete(v);
20 q=next
21 }
22 return all?[]:0
23 };
Execution canvas Active ChangedSTEP 1 Expand shortest transformation paths Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.
Worked example and algorithm walkthrough Topic: Graphs · Traversal and connectivity
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 {
"start": "hit",
"end": "cog",
"words": [
"hot",
"dot",
"dog",
"lot",
"log",
"cog"
],
"all": true
} Execution steps Expand shortest transformation paths Computed output [
[
"hit",
"hot",
"dot",
"dog",
"cog"
],
[
"hit",
"hot",
"lot",
"log",
"cog"
]
] JavaScript reference implementation const solve = ({
start,end,words,all
},s)=>{
let remaining=new Set(words),q=[[start]],o=[];
while(q.length){
let next=[],used=new Set;
for(let p of q){
let u=p.at(-1);
if(u===end)o.push(p);
else for(let v of remaining)if([...u].filter((x,i)=>x!==v[i]).length===1){
next.push(p.concat(v));
used.add(v)
}
}
s("Expand shortest transformation paths",{
Paths:q,Next:next,Solutions:o
});
if(o.length)return all?o:o[0].length;
for(let v of used)remaining.delete(v);
q=next
}
return all?[]:0
};Continue learning Practice related DSA questions in the same topic.