Remove Repeats from Sorted List
Easy
Question
Given the head of a sorted linked list, delete all repeats and return the manipulated linked list. The returned linked list should still be sorted.
Try to solve this problem in O(n) time and O(1) space.
Input: head = [1 -> 1 -> 2 -> 3 -> 3]
Output: [1 -> 2 -> 3]
Input: head = [5 -> 5 -> 5]
Output: [5]
Clarify the problem
What are some questions you'd ask an interviewer?
Understand the problem
What is the resulting list after removing all repeats from the following sorted list? head = [4 -> 7 -> 8 -> 8 -> 9 -> 10 -> 11 -> 11 -> 11 -> 15 -> 15 -> 20]
[4 -> 7 -> 9 -> 10 -> 20]
[20 -> 10 -> 9 -> 7 -> 4]
[4 -> 7 -> 8 -> 9 -> 10 -> 11 -> 15 -> 20]
[20 -> 15 -> 11 -> 10 -> 9 -> 8 -> 7 -> 4]
All test cases pass! 🎉
Time limit exceeded
InputExpected OutputActual Output
Standard OutputScroll down...
Login or signup to save your code.
Uh oh... looks like you don't yet have access.
Not sure what this unlocks? Check out a free pattern section.