PTC Interview Question

Given a linked list that its nodes have a random pointer to another node in the list. Write a code to clone the list.

Interview Answer

Anonymous

Feb 2, 2020

First build a copy of the linked list without coping the "random" property, and build hash-map from the old linked list to the new linked list. Than go over the linked list again and map the random property using the hash-map built before. solution in O(n)