Remove Duplicates from a Sorted Linked List –CA23
My Thinking and Approach Introduction In this problem, I was given a sorted linked list and asked to remove duplicate elements. Since the list is already sorted, duplicates will always appear next ...

Source: DEV Community
My Thinking and Approach Introduction In this problem, I was given a sorted linked list and asked to remove duplicate elements. Since the list is already sorted, duplicates will always appear next to each other. This made the problem easier to approach. Problem Statement Given a sorted linked list Remove duplicate nodes Return the updated list My Initial Thought Initially, I thought: Store elements in a set Rebuild the linked list But this uses extra space, which is not required here. Key Observation Because the list is sorted: Duplicate values are always adjacent So I only need to compare current node with the next node Optimized Approach I decided to: Traverse the list once If current node value equals next node value: Skip the next node Otherwise: Move forward My Approach Start with curr = head Traverse while curr and curr.next are not null Steps: If curr.data == curr.next.data: Remove duplicate by skipping node curr.next = curr.next.next Else: Move to next node Code (Java) class So