Back to questionsDSA Visualizers: 388 Coding Questions Delete Middle Node visualizer Learn Delete Middle Node with a step-by-step Linked Lists visualizer, JavaScript source code and a worked example. Practice rewiring and advanced.
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 {
"a": [
1,
2,
3,
4,
5
],
"n": 2,
"mode": "middle"
} Code Visuals
JavaScript reference implementation · highlighted trace statement
1 const solve = ({
2 a,n,mode
3 },s)=>{
4 let l=0 ,r=0 ;
5 if (mode==="nth"){
6 r=n;
7 while (r<a.length){
8 s("Move gap pointers",{
9 Nodes:a,Pointers:[l,r]
10 });
11 l++;
12 r++
13 }
14 }else {
15 while (r+1 <a.length){
16 l++;
17 r+=2 ;
18 s("Move slow and fast",{
19 Nodes:a,Pointers:[l,r]
20 })
21 }
22 }
23 a.splice(l,1 );
24 s("Bypass target node",{
25 Nodes:a
26 });
27 return a
28 };
Execution canvas Active ChangedSTEP 1 Move slow and fast Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.
Worked example and algorithm walkthrough Topic: Linked Lists · Rewiring and advanced
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": [
1,
2,
3,
4,
5
],
"n": 2,
"mode": "middle"
} Execution steps Move slow and fast Bypass target node Computed output [
1,
2,
4,
5
] JavaScript reference implementation const solve = ({
a,n,mode
},s)=>{
let l=0,r=0;
if(mode==="nth"){
r=n;
while(r<a.length){
s("Move gap pointers",{
Nodes:a,Pointers:[l,r]
});
l++;
r++
}
}else{
while(r+1<a.length){
l++;
r+=2;
s("Move slow and fast",{
Nodes:a,Pointers:[l,r]
})
}
}
a.splice(l,1);
s("Bypass target node",{
Nodes:a
});
return a
};Continue learning Practice related DSA questions in the same topic.