Solution to remove duplicates from linked list