Remove Duplicates from Sorted List Visualization & Animation

Removes consecutive duplicate nodes from a sorted linked list in-place; O(n) time, O(1) space.

## What is it? Remove all duplicate nodes from a sorted singly linked list so that each value appears only once. ## How it works - Use a single pointer `curr` starting at `head` - If `curr.val == curr.next.val` → skip `curr.next` by setting `curr.next = curr.next.next` - Otherwise → advance `curr = curr.next` - Repeat until `curr.next == null` ## When to use - Deduplication of sorted data in a linked list - Pre-processing step in merge/sort algorithms on lists - Variant: "Remove all duplicates" (delete every node with a duplicate value, not just the extra copies) ## Key Points - Works only on **sorted** lists — duplicates are guaranteed to be adjacent - O(n) time, O(1) space — in-place pointer manipulation - The node itself is not freed in garbage-collected languages; just its reference is removed

Category: algorithms

Difficulty: beginner

Time Complexity: O(n)

Space Complexity: O(1)

Remove Duplicates from Sorted List

beginner

Removes consecutive duplicate nodes from a sorted linked list in-place; O(n) time, O(1) space.

Start
null1384712041215638472492121563156749213NULL1567curr
Starting with sorted list [1, 1, 2, 3, 3]. We walk with a single curr pointer and remove any node whose value equals curr.next.val.