← 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
Hiring now
Get the Apple interview, not just the prep
landed applies to roles like these for you, on each company’s own site, with answers written for the role.
Get 5x interviews10 free auto-applies. No card.
Next question