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

3 Answers

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
0

The key in generic questions like this, is to make sure to cover the fundamentals. There's usually a back-and-forth with the interviewer.

Might be worth doing a mock interview with one of the Microsoft Senior Software Development Engineer experts on Prepfully? Really helps to get some real-world practice and guidance.

prepfully.com/practice-interviews

Anonymous on 31-May-2020

One or more comments have been removed.
Please see our Community Guidelines or Terms of Service for more information.

Add Answers or Comments

To comment on this, Sign In or Sign Up.