As reported: Walmart Senior Software Engineer hiring drive, round 1 DSA in person (Bangalore, Oct 2025): Copy List with Random Pointer. A hash map solution was accepted as a start; the interviewer then asked for
O(1)extra space. Word Search was the second question.
Each node of a linked list has val, next and random (pointing to any node or null). Return a deep copy: new nodes only, with next and random pointing into the copy. The original list must be left unchanged.
This is LeetCode 138 — Copy List with Random Pointer.
Example
[[7,null],[13,0],[11,4],[10,2],[1,0]] -> [[7,null],[13,0],[11,4],[10,2],[1,0]]
Each pair is [val, random_index].
Follow-ups
- Use
O(1)extra space (besides the copy itself).
Constraints: 0 ≤ n ≤ 1000; -10^4 ≤ val ≤ 10^4.
Code runner format: one line: the list as [[val, random_index], …]. Implement copyRandomList(head); the harness checks the copy shares no nodes with the original and prints it in the same format.