← All questions
Coding
Clone a Linked List with Random Pointers
Asked at
Apple
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
- 01Explain the map solution first.
- 02Map every original node to a clone.
- 03Wire next and random through the map.
- 04Optionally interleave clones for O(1) extra space.
- 05Separate the two lists carefully.
Reference answer
Then expect these follow-ups
Why does the interleaving trick avoid a map?
Tests: correctness reasoning
How would this generalize to an arbitrary graph?
Tests: follow-up reasoning
Free to read · better with Enzo
Practice this out loud with Enzo
Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.
Next question