Round 1
Questions: Given the head of an unsorted linked list, remove all duplicate nodes such that each value appears only once in the final list. The relative order of nodes should be preserved.
Return the head of the modified linked list.
Example 1
Input:
head = [1, 2, 3, 2, 4, 3, 5]
Output:
[1, 2, 3, 4, 5]
Explanation:
- The first occurrence of each value is kept.
- The second occurrences of 2 and 3 are removed.
Example 2
Input:
head = [5, 1, 2, 1, 3, 2, 4]
Output:
[5, 1, 2, 3, 4]
Explanation:
- The first occurrence of each value is kept.
- The second occurrences of 1 and 2 are removed.
Example 3
Input:
head = [1, 1, 1, 1, 1]
Output:
[1]
Explanation:
- All duplicate occurrences of 1 are removed.
Constraints:
- The number of nodes in the linked list is in the range [0, 10^4].
- -10^5 <= Node.val <= 10^5
- The list is unsorted.
Follow-Up Question
Can you solve this problem without using extra space (i.e., using only O(1) additional memory)?
Candidate's Approach
No approach provided.
Interviewer's Feedback
No feedback provided.