DSAMaster Logo
DSAMaster
BackmediumLinked Lists

Remove Duplicate Nodes from Linked List

Problem Description

Implement a function to remove duplicate nodes from a given linked list, preserving the original order of nodes.

Example 1
Input
1 -> 2 -> 2 -> 1 -> 3
Output
1 -> 2 -> 3

Explanation: The function removes duplicate nodes (2, 1) from the linked list, preserving the original order.

Example 2
Input
1 -> 1 -> 2 -> 2 -> 2
Output
1 -> 2

Explanation: The function removes all duplicate nodes (1, 2) from the linked list, preserving the original order.

Example 3
Input
1 -> 2 -> 3 -> 4 -> 5
Output
1 -> 2 -> 3 -> 4 -> 5

Explanation: The function does not remove any nodes from the linked list since all nodes are unique.

Constraints

  • The linked list nodes may contain integers or strings.
  • The linked list may be empty or contain only one node.
  • The function should preserve the original order of nodes.
00:00
Loading...

Sign in to Solve

Access the full code editor, ThinkBuddy AI hints, and track your progress.

Sign in Free
Test Cases & Output
Enter test input here...
Click "Run Code" to execute