Standard Bar Linked List · Medium Problems of DLL O(n) · O(1)
An inventory rail is value-sorted, but a scanner glitch booked the same SKU several times in a row. Operations wants exactly one entry per distinct SKU, first occurrence kept, and the two-way links re-fused so the rail stays coherent. Because duplicates can only be adjacent in a sorted run, a single forward pass that remembers the value of the last kept entry is enough to squeeze out every repeat.
Input: An array head of n node values forming a doubly linked list sorted in non-decreasing order.
Output: The values of the list after all duplicate nodes are unlinked, read from the head.
1 <= n <= 10^5-10^9 <= head[i] <= 10^9Input: {"head":[1,1,1,2,3,4]}
Output: [1,2,3,4]
The run of three 1s collapses to its first occurrence; the sorted tail is untouched.
Input: {"head":[1,2,2,3,3,4,4]}
Output: [1,2,3,4]
Three separate duplicate runs each squeeze down to a single entry.