Practice Copy List with Random Pointer
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Create a deep copy of a linked list whose nodes have next and random pointers. Each random pointer is null or targets any node in the original list. Allocate a corresponding new node for every original node, preserving values and pointer structure; no copied pointer may target an original node. Return the copied head. The serialized representation uses [val, random_index] for each node: random_index is the zero-based target position or null. The function receives the original head, not those serialization pairs.
Source: Copy List with Random Pointer on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
head = [[7,null],[13,0],[11,4],[10,2],[1,0]]
[[7,null],[13,0],[11,4],[10,2],[1,0]]
# Example 2
head = [[1,1],[2,1]]
[[1,1],[2,1]]
# Example 3
head = [[3,null],[3,0],[3,null]]
[[3,null],[3,0],[3,null]]
Constraints
Related LeetCode Problems
Practice more problems similar to Copy List with Random Pointer.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.