`{"id":"fc0dea57-c81a-47ab-9516-3c59f1a4b4b0","name":"Remove Duplicate From Sorted Linkedlist","description":"1. You are give a single sorted linkedlist of numbers. \r\n2. remove all duplicate nodes such that duplicate numbers appear once and Return the remaning linked list.","inputFormat":"1->1->1->4->5->6->6->7->8->9->9->9->null","outputFormat":"1->4->5->6->7->8->9->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":"print()"}},"points":10,"difficulty":"easy","sampleInput":"12\r\n1 1 1 4 5 6 6 7 8 9 9 9","sampleOutput":"1 4 5 6 7 8 9","questionVideo":"","hints":[],"associated":[{"id":"691ee8fa-6960-4e5c-be73-9790baeddbc8","name":"Why we are using the ‘this.’ keyword here?(Q- RDSL)","slug":"why-we-are-using-the-this-keyword-here-q-rdsl","type":4},{"id":"b3332d21-7a5c-4899-ac43-1804a1190a21","name":"Why we are removing the form first from the original list?(Q- RDSL)","slug":"why-we-are-removing-the-form-first-from-the-original-list-q-rdsl","type":4},{"id":"c296d660-410d-43b3-8da7-4d34ed80c729","name":"why we are adding at last to the new list?(Q- RDSL)","slug":"why-we-are-adding-at-last-to-the-new-list-q-rdsl","type":4}],"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":"7fba157d-21c0-4004-828c-b405d033f213","name":"Remove Duplicate From Sorted Linkedlist","slug":"remove-duplicate-from-sorted-linkedlist","type":1}],"next":{"id":"1a0fb5b0-d299-41f5-8832-69c3c5f3a1ef","name":"Remove Duplicate From Sorted Linkedlist Easy MCQ","type":0,"slug":"remove-duplicate-from-sorted-linkedlist-easy-mcq"},"prev":{"id":"bccb98d4-5126-4a81-afc2-4eaafb497a5e","name":"Intersection node in two linked lists using Floyd cycle method.","type":3,"slug":"intersection-node-in-two-linked-lists-using-floyd-cycle-method"}}}`

# Remove Duplicate From Sorted Linkedlist

1. You are give a single sorted linkedlist of numbers. 2. remove all duplicate nodes such that duplicate numbers appear once and Return the remaning linked list.

`{"id":"fc0dea57-c81a-47ab-9516-3c59f1a4b4b0","name":"Remove Duplicate From Sorted Linkedlist","description":"1. You are give a single sorted linkedlist of numbers. \r\n2. remove all duplicate nodes such that duplicate numbers appear once and Return the remaning linked list.","inputFormat":"1->1->1->4->5->6->6->7->8->9->9->9->null","outputFormat":"1->4->5->6->7->8->9->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":"print()"}},"points":10,"difficulty":"easy","sampleInput":"12\r\n1 1 1 4 5 6 6 7 8 9 9 9","sampleOutput":"1 4 5 6 7 8 9","questionVideo":"","hints":[],"associated":[{"id":"691ee8fa-6960-4e5c-be73-9790baeddbc8","name":"Why we are using the ‘this.’ keyword here?(Q- RDSL)","slug":"why-we-are-using-the-this-keyword-here-q-rdsl","type":4},{"id":"b3332d21-7a5c-4899-ac43-1804a1190a21","name":"Why we are removing the form first from the original list?(Q- RDSL)","slug":"why-we-are-removing-the-form-first-from-the-original-list-q-rdsl","type":4},{"id":"c296d660-410d-43b3-8da7-4d34ed80c729","name":"why we are adding at last to the new list?(Q- RDSL)","slug":"why-we-are-adding-at-last-to-the-new-list-q-rdsl","type":4}],"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":"7fba157d-21c0-4004-828c-b405d033f213","name":"Remove Duplicate From Sorted Linkedlist","slug":"remove-duplicate-from-sorted-linkedlist","type":1}],"next":{"id":"1a0fb5b0-d299-41f5-8832-69c3c5f3a1ef","name":"Remove Duplicate From Sorted Linkedlist Easy MCQ","type":0,"slug":"remove-duplicate-from-sorted-linkedlist-easy-mcq"},"prev":{"id":"bccb98d4-5126-4a81-afc2-4eaafb497a5e","name":"Intersection node in two linked lists using Floyd cycle method.","type":3,"slug":"intersection-node-in-two-linked-lists-using-floyd-cycle-method"}}}`

Editor

# Remove Duplicate From Sorted Linkedlist

easy

1. You are give a single sorted linkedlist of numbers. 2. remove all duplicate nodes such that duplicate numbers appear once and Return the remaning linked list.

0 <= N <= 10^6

## Format

### Input

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

### Output

1->4->5->6->7->8->9->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;}1 4 5 6 7 8 9`

Discussions

Show Discussion

Related Resources