Medium: Clone a linked list with random pointers

Asked atBoston Consulting Group
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+
  1. 01Clarify whether original list may be temporarily mutated
  2. 02Choose map or interleaving strategy
  3. 03Create each clone exactly once
  4. 04Wire next and random pointers from known clones
  5. 05Separate lists and verify null random pointers

Reference answer

Then expect these follow-ups

  • Which approach would you choose in production and why?

    Tests: correctness reasoning

  • How would you verify topology equality without pointer equality?

    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