Microsoft Interview Question

Remove the duplicates from a linked-list.

Interview Answers

Anonymous

Nov 4, 2010

I asked what was stored in the linked-list nodes, and the interviewer said "integers". I made a HashMap to store the values from the ListNodes. I iterated through the list, checking if they exist in the HashMap. If not, add the value of each node to the HashMap and move on. If so, remove the item from the LinkedList and move on. I'm not sure if this is the fastest way to do this.

Anonymous

Oct 10, 2011

Rather than "store the values from the list node", you should use the value as key for the hashing functions, and just mark its value to 1 if this is the first time you saw it, remove if its not the first time.