Microsoft Interview Question: Clone a linked list that has ... | Glassdoor.co.in

Interview Question

Senior Software Development Engineer Interview Redmond, WA (US)

Clone a linked list that has a cycle (do not fix the

  cycle). Is there a way to uniquely identify a node without relying on a hash code?
Answer

Interview Answer

1 Answer

0

Use a dictionary. If node.next has entry in dictionary you have found the cycle. So your newly created node will point to a clone of this node and method returns.
A unique way of identifying a node would be to use the address of the variable...in C you could use the address returned upon allocation as a unique way of identifying node.

Interview Candidate on 08-Jul-2015

Add Answers or Comments

To comment on this, Sign In or Sign Up.