Copy List with Random Pointer
A linked list stores val, next, and random. The random pointer is either null or points at some node of the same list, so the random pointers on their own can form chains, self references, and cycles of any length.
Return a deep copy of the list. The copy keeps every value in the same order, and each copied node points at the copied node that matches the original random target. Build the answer from new nodes: no returned node may be one of the nodes your code created to represent the input, and every next and random pointer must land inside the returned list.
The list is written as [value, randomIndex] pairs in list order. randomIndex = -1 means random is null; any other value is the position of the target node inside the same list. Return the copy in the same pair form, so position i of the answer describes copied node i.
Copy List with Random Pointer
A linked list stores `val`, `next`, and `random`. The `random` pointer is either `null` or points at some node of the same list, so the random pointers on their own can form chains, self references, and cycles of any length.