Deep Copy with Random Pointers
A linked list with random pointers requires a deep copy in which every original node gets a new corresponding node and each new random pointer refers to the copied target rather than the original target. A HashMap provides the simplest and most explicit solution.
Time complexity: O(n).
Auxiliary space: O(n) for the mapping.
The map ensures every original node maps to exactly one copied node.
Random pointers may point forward, backward, or to the same node.
An O(1) auxiliary-space solution is possible by interleaving copied nodes with original nodes before separating the lists.