Workspace Copy List With Random Pointer
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Copy List with Random Pointer visualizer

Learn Copy List with Random Pointer with a step-by-step Linked Lists visualizer, JavaScript source code and a worked example. Practice rewiring and advanced.

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
{
  "v": [
    7,
    13,
    11
  ],
  "r": [
    null,
    0,
    1
  ]
}

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = ({
v,r
},s)=>{
let o=v.map(x=>[x,null]);
for(let i=0;
i<v.length;
i++){
o[i][1]=r[i];
s("Wire copied random pointer by identity",{
Original:v,Random:r,Copy:o
},[i])
}
return o
};

Execution canvas

Active Changed
STEP 1

Wire copied random pointer by identity

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

Original3 items
Random3 items
Copy3 rows
Keyboard: Space to play · Left / Right to stepExplore next problem

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

{
  "v": [
    7,
    13,
    11
  ],
  "r": [
    null,
    0,
    1
  ]
}

Execution steps

  1. Wire copied random pointer by identity

Computed output

[
  [
    7,
    null
  ],
  [
    13,
    0
  ],
  [
    11,
    1
  ]
]
JavaScript reference implementation
const solve = ({
  v,r
},s)=>{
  let o=v.map(x=>[x,null]);
  for(let i=0;
  i<v.length;
  i++){
    o[i][1]=r[i];
    s("Wire copied random pointer by identity",{
      Original:v,Random:r,Copy:o
    },[i])
  }
  return o
};

Continue learning

Practice related DSA questions in the same topic.