Popular Posts

Monday, August 1, 2011

Problem:
  Write code to remove duplicates from an unsorted linked list
Solution:
  1. Have two pointers ptr1 and ptr2.
  2. For each node ptr1 visits check from head [head  to node before ptr1] whether that data is already present.
  3. If so, remove the ptr1 node.
  4. return the new list without any duplicates
Complexity: O(n^2)
Code:





No comments:

Post a Comment