Deep Copy of a Linked List with Random Links

Asked at Snowflake · Coding Questions · Difficulty: Medium · Last asked Dec 14, 2025

A linked list node holds an integer `val`, a `next` pointer to the following node, and a `random` pointer that may point to any node of the same list (including the node itself) or to nothing. Build a deep copy of such a list: a completely independent clone in which no node is shared with the original, the `next` order is the same, and every `random` pointer connects the same positions as in the original.

Loading the problem…