ASAPUtils Logo ASAPUtils
Week 5

Copy List with Random Pointer

Copy List with Random Pointer using the O(1)-space interleaving technique, with C++ and JavaScript solutions, a three-pass proof, hash-map alternative, random-edge traps, and an interactive deep-copy trace.

medium Linked Lists O(n) time · O(1) auxiliary space Open on LeetCode ↗

The problem

Deep-copy a linked list whose nodes have both next and arbitrary random references, so every edge in the returned list points only to copied nodes.

A.random = C and B.random = A -> copyA.random = copyC and copyB.random = copyA

Related Problems