`{"id":"038b4f3f-b120-4f02-8018-2022be338007","name":"Remove All Duplicates From Sorted Linkedlist","description":"1. You are give a single sorted linkedlist of numbers. \r\n2. remove all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the remaning linked list.\r\n","inputFormat":"1->1->1->4->5->6->6->7->8->9->9->9->null","outputFormat":"4->5->7->8->null","constraints":"0 &lt;= N &lt;= 10^6","sampleCode":{"cpp":{"code":"#include <iostream>\r\nusing namespace std;\r\n\r\nclass ListNode\r\n{\r\npublic:\r\n int val = 0;\r\n ListNode *next = nullptr;\r\n\r\n ListNode(int val)\r\n {\r\n this->val = val;\r\n }\r\n};\r\n\r\nListNode *removeDuplicates(ListNode *head)\r\n{\r\n return nullptr;\r\n}\r\n// Input_code===================================================\r\n\r\nListNode *makeList(int n)\r\n{\r\n ListNode *dummy = new ListNode(-1);\r\n ListNode *prev = dummy;\r\n while (n-- > 0)\r\n {\r\n int val;\r\n cin >> val;\r\n prev->next = new ListNode(val);\r\n prev = prev->next;\r\n }\r\n return dummy->next;\r\n}\r\n\r\nvoid printList(ListNode *node)\r\n{\r\n ListNode *curr = node;\r\n while (curr != nullptr)\r\n {\r\n cout << curr->val << \" \";\r\n curr = curr->next;\r\n }\r\n cout << endl;\r\n}\r\n\r\nint main()\r\n{\r\n int n;\r\n cin >> n;\r\n ListNode *head = makeList(n);\r\n\r\n head = removeDuplicates(head);\r\n printList(head);\r\n\r\n return 0;\r\n}"},"java":{"code":"import java.util.*;\r\n\r\nclass Main {\r\n public static Scanner scn = new Scanner(System.in);\r\n\r\n public static class ListNode {\r\n int val = 0;\r\n ListNode next = null;\r\n\r\n ListNode(int val) {\r\n this.val = val;\r\n }\r\n }\r\n\r\n public static ListNode removeDuplicates(ListNode head) {\r\n return null;\r\n }\r\n\r\n // InFput_code===================================================\r\n\r\n public static void printList(ListNode node) {\r\n while (node != null) {\r\n System.out.print(node.val + \" \");\r\n node = node.next;\r\n }\r\n }\r\n\r\n public static ListNode makeList(int n) {\r\n ListNode dummy = new ListNode(-1);\r\n ListNode prev = dummy;\r\n while (n-- > 0) {\r\n prev.next = new ListNode(scn.nextInt());\r\n prev = prev.next;\r\n }\r\n\r\n return dummy.next;\r\n }\r\n\r\n public static void main(String[] args) {\r\n ListNode head = makeList(scn.nextInt());\r\n\r\n ListNode ans = removeDuplicates(head);\r\n printList(ans);\r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"12\r\n1 1 1 4 5 6 6 7 8 9 9 9","sampleOutput":"4 5 7 8 ","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"1e4c8949-5890-4d15-be5b-6601c7e2029a","name":"Linked List For Intermediate","slug":"linked-list-for-intermediate-637","type":0},{"id":"95331217-dac7-42f2-8312-752d61f2341a","name":"Remove All Duplicates From Sorted Linkedlist","slug":"remove-all-duplicates-from-sorted-linkedlist","type":1}],"next":{"id":"d505e708-ba11-4ac0-8f15-1b2783063bba","name":"Remove All Duplicates From Sorted Linkedlist MCQ","type":0,"slug":"remove-all-duplicates-from-sorted-linkedlist-mcq"},"prev":{"id":"5d0daff3-0af0-40e7-a54b-aac0fcd68f32","name":"Remove Duplicate From Sorted Linkedlist","type":3,"slug":"remove-duplicate-from-sorted-linkedlist"}}}`

# Remove All Duplicates From Sorted Linkedlist

1. You are give a single sorted linkedlist of numbers. 2. remove all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the remaning linked list.

`{"id":"038b4f3f-b120-4f02-8018-2022be338007","name":"Remove All Duplicates From Sorted Linkedlist","description":"1. You are give a single sorted linkedlist of numbers. \r\n2. remove all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the remaning linked list.\r\n","inputFormat":"1->1->1->4->5->6->6->7->8->9->9->9->null","outputFormat":"4->5->7->8->null","constraints":"0 &lt;= N &lt;= 10^6","sampleCode":{"cpp":{"code":"#include <iostream>\r\nusing namespace std;\r\n\r\nclass ListNode\r\n{\r\npublic:\r\n int val = 0;\r\n ListNode *next = nullptr;\r\n\r\n ListNode(int val)\r\n {\r\n this->val = val;\r\n }\r\n};\r\n\r\nListNode *removeDuplicates(ListNode *head)\r\n{\r\n return nullptr;\r\n}\r\n// Input_code===================================================\r\n\r\nListNode *makeList(int n)\r\n{\r\n ListNode *dummy = new ListNode(-1);\r\n ListNode *prev = dummy;\r\n while (n-- > 0)\r\n {\r\n int val;\r\n cin >> val;\r\n prev->next = new ListNode(val);\r\n prev = prev->next;\r\n }\r\n return dummy->next;\r\n}\r\n\r\nvoid printList(ListNode *node)\r\n{\r\n ListNode *curr = node;\r\n while (curr != nullptr)\r\n {\r\n cout << curr->val << \" \";\r\n curr = curr->next;\r\n }\r\n cout << endl;\r\n}\r\n\r\nint main()\r\n{\r\n int n;\r\n cin >> n;\r\n ListNode *head = makeList(n);\r\n\r\n head = removeDuplicates(head);\r\n printList(head);\r\n\r\n return 0;\r\n}"},"java":{"code":"import java.util.*;\r\n\r\nclass Main {\r\n public static Scanner scn = new Scanner(System.in);\r\n\r\n public static class ListNode {\r\n int val = 0;\r\n ListNode next = null;\r\n\r\n ListNode(int val) {\r\n this.val = val;\r\n }\r\n }\r\n\r\n public static ListNode removeDuplicates(ListNode head) {\r\n return null;\r\n }\r\n\r\n // InFput_code===================================================\r\n\r\n public static void printList(ListNode node) {\r\n while (node != null) {\r\n System.out.print(node.val + \" \");\r\n node = node.next;\r\n }\r\n }\r\n\r\n public static ListNode makeList(int n) {\r\n ListNode dummy = new ListNode(-1);\r\n ListNode prev = dummy;\r\n while (n-- > 0) {\r\n prev.next = new ListNode(scn.nextInt());\r\n prev = prev.next;\r\n }\r\n\r\n return dummy.next;\r\n }\r\n\r\n public static void main(String[] args) {\r\n ListNode head = makeList(scn.nextInt());\r\n\r\n ListNode ans = removeDuplicates(head);\r\n printList(ans);\r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"12\r\n1 1 1 4 5 6 6 7 8 9 9 9","sampleOutput":"4 5 7 8 ","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"1e4c8949-5890-4d15-be5b-6601c7e2029a","name":"Linked List For Intermediate","slug":"linked-list-for-intermediate-637","type":0},{"id":"95331217-dac7-42f2-8312-752d61f2341a","name":"Remove All Duplicates From Sorted Linkedlist","slug":"remove-all-duplicates-from-sorted-linkedlist","type":1}],"next":{"id":"d505e708-ba11-4ac0-8f15-1b2783063bba","name":"Remove All Duplicates From Sorted Linkedlist MCQ","type":0,"slug":"remove-all-duplicates-from-sorted-linkedlist-mcq"},"prev":{"id":"5d0daff3-0af0-40e7-a54b-aac0fcd68f32","name":"Remove Duplicate From Sorted Linkedlist","type":3,"slug":"remove-duplicate-from-sorted-linkedlist"}}}`

Editor

# Remove All Duplicates From Sorted Linkedlist

easy

1. You are give a single sorted linkedlist of numbers. 2. remove all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the remaning linked list.

0 <= N <= 10^6

## Format

### Input

1->1->1->4->5->6->6->7->8->9->9->9->null

4->5->7->8->null

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}12 1 1 1 4 5 6 6 7 8 9 9 9```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}4 5 7 8 `

Discussions

Show Discussion

Related Resources