“Find a recurring element in a linked list of unicode characters. If a unicode character/s is found to have a duplicate then just delete that repeating node and adjust the list. The constraint was to not to use any extra memory.”
My answer:
Assuming that the unicode char doesn't include surrogate pair char As I am using c#
I don't know how can you find a duplicate character unless you know the values of the previous nodes while traversing the list, and to maintain the previous values you will need extra memory (hash table).
Guys, can you think of any solution to this question? It's an interview question on one of the sites. Also is it possible to solve this in O(n) time?
Here is my Implementation. Can You give feedback on it so that I can make it better?
public static void RemoveDup(Node head)
{
Node current1 = head;
Node current2;
while (current1 != null)
{
current2 = current1;
while (current2 != null)
{
if (current2.Next!=null && current1.Data == current2.Next.Data)
{
Node temp = current2.Next.Next;
current2.Next = temp;
current2=current1;
continue;
}
current2 = current2.Next;
if (current2 == null)
break;
}
current1 = current1.Next;
if (current1 == null)
break;
}
}