Interview Questions

242. How will you delete duplicate odd numbers from a linked list? ....

Microsoft Interview Questions and Answers


(Continued from previous question...)

242. How will you delete duplicate odd numbers from a linked list? ....

Question:
How will you delete duplicate odd numbers from a linked list? (delete only duplicates, keep one copy, list is not sorted) Interviewer was expecting O(n) answer. He didn't say anything clear about the extra space


maybe an answer:


public static List getDupNodes(Node n)
{
HashSet h = new HashSet<Node>();
while (n.next != null)
{
if ((n.data % 2 != 0) && (h.Contains(n)))
{
//do nothing///
}
else
{
h.Add(n);
}
n = n.next;
}
return h.ToList<Node>();

}

(Continued on next question...)

Other Interview Questions