This question evaluates understanding of singly linked list data structures and in-place node manipulation to remove repeated values while preserving relative order, testing competencies in pointer management and duplicate-detection.
You are given the head of a singly linked list of integers. Modify the list in place so that it contains only the first occurrence of each value (i.e., remove any node whose value has already appeared earlier in the list).
data
(integer)
next
(reference to next node, or
null
at the tail)
Return the head of the updated linked list.
3 -> 4 -> 3 -> 6
3 -> 4 -> 6
3 -> 4 -> 3 -> 2 -> 6 -> 1 -> 2 -> 6
3 -> 4 -> 2 -> 6 -> 1