Back to problems

Copy List with Random Pointer

Algorithm · Snowflake · Medium

A linked list containing n elements is provided in the following test representation: nodes[i] = [val, randomIndex] val gives the value stored in node i. randomIndex identifies the node targeted by that node's random pointer; it is -1 when random does not point anywhere. Create and return an independent copy of this list using the identical representation. Your copied list must retain the original next sequence as well as every random pointer relationship. Examples Example…

Checking your access…