Remove Duplicates from Sorted List
EasyLinked Listtwo pointers
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
The head of a singly linked list sorted in non-decreasing order is given. Remove nodes so that each distinct value appears exactly once, keeping the first node of every run of equal values.
Return the head of the list after removal. It is still sorted. An empty list returns an empty list.
Examples
Input: head = [1,1,2]
Output: [1,2]
The second 1 is dropped.
Input: head = [1,1,2,3,3]
Output: [1,2,3]
One copy each of 1, 2 and 3 remains.
Constraints
- 0 <= number of nodes <= 10^4
- -100 <= Node.val <= 100
- The list is sorted in non-decreasing order.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.