Copy List with Random Pointer Problem

Copy List with Random Pointer Problem — ExecCode Medium DSA Practice

Solve the Copy List with Random Pointer problem on ExecCode. Free online medium DSA practice in Linked List. Write and run code in Java, C++, Python — no signup required to run.

Problem description

A linked list has each node with an extra random pointer that could point to any node or null. Construct a deep copy of the list.

Examples

Input head = [[7, null], [13, 0], [11, 4], [10, 2], [1, 0]]; Output [[7, null], [13, 0], [11, 4], [10, 2], [1, 0]]. Input head = [[1, 1], [2, 1]]; Output [[1, 1], [2, 1]]. Input head = [[3, null], [3, 0], [3, null]]; Output [[3, null], [3, 0], [3, null]]

Constraints

0 ≤ n ≤ 1000 -10⁴ ≤ Node.val ≤ 10⁴ random is null or points to a node in the list.

Practice Copy List with Random Pointer free on ExecCode. Browse DSA problems, topic map, and placement guides.