Skip to main content
Intermediatecoding Verified

Clone a linked list in which every node has a next pointer and a random pointer to any node (or null).

ReportedSource: GeeksforGeeks interview experience: Amazon SDE intern 2024

Quick answerFree

Either map old node -> new node (by identity) in two passes, or interleave copies after originals, set random = original.random.next, then split the lists for O(1) extra space.

Detailed answer· 98 words

Interview Prep

Unlock the full answer with Interview Prep

Get a 98-word model answer and a runnable reference solution, plus 61 more DSA questions.

Also in Pro (₹499 / 90 days).

Reference solution· runs in the browser sandbox

Interview Prep
Unlock with Interview Prep

+ 61 more DSA questions in Interview Prep, each with the full answer.

Discussion