Copy List with Random Pointer
mediumDeep copy a linked list where each node has a next and a random pointer
Copy List with Random Pointer
Key Insight
Hash map from original→clone lets you wire random pointers in a second pass
Step 1Original List
Random: 1→3, 2→1, 3→2
1
2
3
null
Each node has next and random pointers. Random: 1→3, 2→1, 3→2.
1 / 5