Interview Questions

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

Microsoft Interview Questions and Answers


(Continued from previous question...)

195. 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.


maybe an answer:


public static List<Node> getDupNodes(Node n) { HashSet<Node> 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