Copy List with Random Pointer
A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null. Construct a deep copy of the list.

30:00

Copy List with Random Pointer
medium
Topics
Companies

A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null. Construct a deep copy of the list.

Example 1:
Input: [[7,-1],[13,0],[11,4],[10,2],[1,0]]
Output: [[7,null],[13,0],[11,4],[10,2],[1,0]]
Constraints:
  • 0n10000 \leq n \leq 1000

  • 104Node.val104-10^4 \leq \text{Node.val} \leq 10^4

  • Node.random is null or a node in the linked list.

Input
arr =[[7,-1],[13,0],[11,4],[10,2],[1,0]]

Deep copy with random pointers

1. Interleave
2. Random
3. Separate
Original:71311101
[7, null]
[13, 0]
[11, 4]
[10, 2]
[1, 0]
Variables
No variables to display
DepthFunction Call
Stack empty
0/4