The Remove Duplicates from Sorted List II interview question is a harder sibling of the basic deduplication problem. Given a sorted linked list, you must delete ALL nodes that have duplicate values — not just the extras, but every occurrence of any duplicated value. Only nodes with unique values should remain in the final list.
This problem is asked at Apple, Microsoft, Meta, Amazon, TikTok, and Google because it requires a more sophisticated two-pointer approach than the simpler version. Managing the prev pointer to stitch around entire groups of duplicates tests careful pointer manipulation. It is used to distinguish candidates who can handle nuanced linked list surgery from those who only know the basic traversal pattern.
The pattern is the two-pointer linked list technique with a dummy head node. Create a sentinel/dummy node pointing to the head to handle edge cases where the head itself is a duplicate. Use prev (starts at dummy) and curr. When curr and curr.next share the same value, advance curr through all nodes with that value, then set prev.next = curr.next to skip the entire group. If no duplicate is detected, simply advance prev. Always advance curr at the end.
List: 1 → 2 → 2 → 3 → 3 → 4
Dummy → 1 → 2 → 2 → 3 → 3 → 4
Result: 1 → 4.
prev when a duplicate group is removed — prev should stay fixed until a clean node is found.1 → 1 → 2 → 2).For the Remove Duplicates from Sorted List II coding problem, always start by adding a dummy/sentinel node — it eliminates head-deletion edge cases and keeps your code clean. The two-pointer linked list interview pattern is central here. Interviewers at Tencent and Adobe often ask you to compare this with the "keep one copy" version — be ready to articulate the difference in prev pointer movement as the key distinction.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Swapping Nodes in a Linked List | Medium | Solve | |
| Partition List | Medium | Solve | |
| Rotate List | Medium | Solve | |
| Delete the Middle Node of a Linked List | Medium | Solve | |
| Remove Nth Node From End of List | Medium | Solve |