DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
LinkedList

Copy List with Random Pointer

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Copy List with Random Pointer** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Hash map old→new, then set next/random **Edge Cases to Consider:** - (1) All random pointers null - (2) All random point to same node - (3) Circular random pointers

Examples

Example 1
Input: [[7,null],[13,0],[11,4],[10,2],[1,0]]
Output: Same structure deep copied
Explanation: Standard case
Example 2
Input: [[1,1],[2,1]]
Output: [[1,1],[2,1]]
Explanation: Two nodes, randoms to each other
Example 3
Input: [[3,null],[3,0],[3,null]]
Output: Same structure
Explanation: Three 3s

Constraints

  • ▪The number of nodes in the list is in the range [0, 500]
  • ▪-100 <= Node.val <= 100
  • ▪Solve in-place without copying node structures

Watch Out For Edge Cases

  • ▪All random pointers null
  • ▪All random point to same node
  • ▪Circular random pointers
Frequently Asked At
AmazonMicrosoftGoogleMetaAdobeUber