Panda Guru LogoPanda
Guru

Removing duplicate nodes in an unsorted linked list

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:

Example 2
Input:

head = [5, 1, 2, 1, 3, 2, 4]

Output:

[5, 1, 2, 3, 4]

Explanation:

Example 3
Input:

head = [1, 1, 1, 1, 1]

Output:

[1]

Explanation:

Constraints:

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.