Medium Lists

Remove Duplicates (Circular Linked List)

Receives an array of integers and builds a circular linked list, where each node holds a value and a next pointer — and the last node's next points back to the head instead of null. It walks the list starting from head's successor using a while loop that stops when it reaches head again, tracking seen values with a set; the first occurrence of each value is kept and any duplicate node is unlinked by redirecting its predecessor's next. Returns the head of the filtered circular list with each value appearing exactly once, preserving the original order.

Visualization

Input

Algorithm code

Custom input

Saved inputs

References