Problem of the day
You are given an unsorted Singly Linked List with 'N' nodes which may contain duplicate elements. You are supposed to remove all duplicate elements from the linked list and keep only the last appearance of elements.
0 <= N <= 5 * 10^5
-10^9 <= data <= 10^9 and data != -1
Where 'data' is the value of elements that exist in the linked list.
Time limit: 1 sec
7 11 13 23 7 11 13 -1
23 7 11 13 -1
7, 11, and 13 have appeared two times, so we remove the first appearance of 7, 11, and 13 and keep their last appearance. Since 7, 11 and 13 are removed, so now the head of the modified, linked list becomes 23.
13 1 19 3 9 -1
13 1 19 3 9 -1
There are no duplicate elements in the given linked list, so there will be no elements deleted. And the modified linked list will be the same as the given linked list.