LeetCode 138 ·
Medium
Copy List with Random Pointer
Deep-copy a linked list where each node also has a random pointer.
Try it
Step through the core mechanic. The simulator below runs the linked list shape this problem is built on.
Walk the pattern
No dedicated step-through for this one yet. The shape is Linked list — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.
The approach
Either a hash map from old node to new node in two passes, or the O(1)-space weave: insert each copy right after its original, wire random pointers from the interleaving, then unzip the two lists.
| Aspect | Value |
|---|---|
| Pattern | Linked list |
| Recognise it by | Deep-copy a list whose nodes point anywhere. |
| Time complexity | O(n) |
| Space complexity | O(1) |
| Difficulty | Medium |
Who asks it
Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.