{"id":3880,"date":"2021-08-16T13:40:42","date_gmt":"2021-08-16T13:40:42","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=3880"},"modified":"2022-11-18T06:58:49","modified_gmt":"2022-11-18T06:58:49","slug":"delete-nodes-that-have-a-greater-value-on-the-right-side","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/","title":{"rendered":"Delete nodes that have a greater value on the right side"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186587688-delete%20nodes%20that%20have%20Greater%20Value%20On%20The%20Right%20Side_Artboard%206.png\" alt=\"\" \/><\/p>\n<h3>Introduction<\/h3>\n<p>We can define a linked list as a sequence of data structures which are connected through links and each node is having a pointer which points to the next node. In this article, we will learn how to  delete nodes which have a greater value on right side<\/p>\n<h3>Problem Statement for delete nodes having greater value on right<\/h3>\n<p>Given a singly linked list, implement a function to delete all the nodes which have a greater valued node on the right side.<\/p>\n<h3>Problem Statement Understanding to delete nodes having greater value on right<\/h3>\n<p>Let\u2019s understand how to delete nodes which have a greater value on right side with the help of some examples.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-1-5.png\" alt=\"\" \/><\/p>\n<p>As 15 has a greater value of 20 on its right and similarly, for 14 we have 20 on its right side, these nodes will be deleted from the linked list.<br \/>\nFor all other nodes, we don\u2019t have a greater valued node on its right. So, they will remain on the linked list.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/resultant-linked-list-1-1.png\" alt=\"\" \/><\/p>\n<p>If our linked list = 1\u21922\u21923\u21924.<\/p>\n<p>Here, each one of 1,2,3 has some number on the right which is greater than it. So, we remove them.<br \/>\nOnly 4 has no greater valued node on its right side, so it will remain in the linked list.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/resultant-linked-list-2-1.png\" alt=\"\" \/><\/p>\n<p>I hope these examples helped you in understanding to delete nodes which have a greater value on right side <\/p>\n<p>Now, can you think of an approach to delete nodes having greater value on right ?<\/p>\n<h3>First Approach to delete nodes having greater value on right: Brute force<\/h3>\n<p>One straightforward thing we can do is for each node, we traverse all the nodes on the right of it and check whether there is any node having a value greater than it or not. If yes, we simply remove that node from the linked list, or else we move to the next node.<\/p>\n<p>We can implement our approach to delete nodes which have a greater value on right side using two nested \u2018for loops\u2019.<\/p>\n<h3>Algorithm to delete nodes having greater value on right, <\/h3>\n<ol>\n<li>Iterate over all nodes using a loop<\/li>\n<li>For each node\n<ul>\n<li>Check if there is a node on its right side with a larger value<\/li>\n<li>If yes, then delete the current node else, move forward.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>Dry Run to delete nodes which have a greater value on right side<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Delete-nodes-which-have-a-greater-value-on-right-side-1.png\" alt=\"\" \/><\/p>\n<h3>Code Implementation for delete nodes having greater value on right,:<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_3882 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_3882 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_3882 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_3882 .wpsm_nav-tabs > li.active > a, #tab_container_3882 .wpsm_nav-tabs > li.active > a:hover, #tab_container_3882 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_3882 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_3882 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_3882 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_3882 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_3882 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_3882 .wpsm_nav-tabs > li > a:hover , #tab_container_3882 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_3882 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_3882 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_3882 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_3882 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_3882 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_3882 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_3882 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_3882 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_3882 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_3882 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_3882 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_3882\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_3882\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_3882_1\" aria-controls=\"tabs_desc_3882_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_3882_2\" aria-controls=\"tabs_desc_3882_2\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C++<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_3882_3\" aria-controls=\"tabs_desc_3882_3\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Java<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_3882_4\" aria-controls=\"tabs_desc_3882_4\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Python<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_3882\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_3882_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"c\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n\r\n\r\n\r\n\r\n#include<bits\/stdc++.h>\r\nusing namespace std;\r\n\r\nstruct Node {\r\n    int val;\r\n    Node* next;\r\n\r\n    Node(int value){\r\n        val = value;\r\n        next = NULL;\r\n    }\r\n};\r\n\r\nvoid push_front(Node** head, int new_val){\r\n    Node* new_node = new Node(new_val);\r\n    new_node->next = *head;\r\n    *head = new_node;\r\n}\r\n\r\nvoid printList(Node* head){\r\n    Node* i = head;\r\n    while(i){\r\n        cout<<i->val<<\" \";\r\n        i = i->next;\r\n    }\r\n    cout<<\"&#92;n\";\r\n}\r\n\r\n\r\nNode* reverse_it(Node* head){\r\n    Node *prev = NULL;\r\n    Node *curr = head, *next;\r\n    while(curr!=NULL){\r\n        next = curr->next;\r\n        curr->next = prev;\r\n        prev = curr;\r\n        curr = next;\r\n    }\r\n    return prev;\r\n}\r\n\r\nvoid del_gr_right(Node** head){\r\n    \/\/ reverse the linked list\r\n    *head  = reverse_it(*head);\r\n\r\n    int mx = (*head)->val;\r\n    Node* prev = *head;\r\n     Node* curr = (*head)->next;\r\n\r\n    while(curr != NULL){\r\n        if(curr->val < mx){\r\n            \/\/ delete curr node\r\n            Node* temp = curr;\r\n            prev->next = curr->next;\r\n            curr = curr->next;\r\n            delete temp;\r\n        } else {\r\n            mx = max(mx, curr->val);\r\n            prev = curr;\r\n            curr = curr->next;\r\n        }\r\n    }\r\n    \/\/ once again reverse it\r\n    *head  = reverse_it(*head);\r\n}\r\n\r\nint main(){\r\n    Node* head = NULL;\r\n\r\n    push_front(&head, 11);\r\n    push_front(&head, 18);\r\n    push_front(&head, 20);\r\n    push_front(&head, 14);\r\n    push_front(&head, 15);\r\n\r\n    printList(head);\r\n    \/\/ 15 14 20 18 11\r\n\r\n    del_gr_right(&head);\r\n\r\n    printList(head);\r\n    \/\/ 20 18 11\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_3882_2\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"cpp\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include<bits stdc++.h>\r\nusing namespace std;\r\n\r\nstruct Node {\r\n    int val;\r\n    Node* next;\r\n\r\n    Node(int value){\r\n        val = value;\r\n        next = NULL;\r\n    }\r\n};\r\n\r\nvoid push_front(Node** head, int new_val){\r\n    Node* new_node = new Node(new_val);\r\n    new_node->next = *head;\r\n    *head = new_node;\r\n}\r\n\r\nvoid printList(Node* head){\r\n    Node* i = head;\r\n    while(i){\r\n        cout<<i->val<<\" \";\r\n        i = i->next;\r\n    }\r\n    cout<<\"&#92;n\";\r\n}\r\n\r\nvoid del_gr_right(Node* head){\r\n    for(Node* i=head; i!=NULL;){\r\n        int value = i->val;\r\n        bool found = false;\r\n        for(Node* j = i->next; j!=NULL; j = j->next){\r\n            if(j->val > value){\r\n                found = 1;\r\n                break;\r\n            }\r\n        }\r\n        if(found){\r\n            \/\/ delete node i\r\n            Node* temp = i->next;\r\n            i->val = i->next->val;\r\n            i->next = i->next->next;\r\n            delete temp;\r\n        }\r\n        else {\r\n            i = i->next;\r\n        }\r\n    }\r\n}\r\n\r\n\r\nint main(){\r\n    Node* head = NULL;\r\n\r\n    push_front(&head, 11);\r\n    push_front(&head, 18);\r\n    push_front(&head, 20);\r\n    push_front(&head, 14);\r\n    push_front(&head, 15);\r\n\r\n    printList(head);\r\n    \/\/ 15 14 20 18 11\r\n\r\n    del_gr_right(head);\r\n\r\n    printList(head);\r\n    \/\/ 20 18 11\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_3882_3\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"Java\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"Java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nclass GreaterValue {\r\n\tNode head; \r\n\r\n\t\/* Linked list Node*\/\r\n\tclass Node {\r\n\t\tint data;\r\n\t\tNode next;\r\n\t\tNode(int d)\r\n\t\t{\r\n\t\t\tdata = d;\r\n\t\t\tnext = null;\r\n\t\t}\r\n\t}\r\n\r\n\t\/* Deletes nodes which have a node with greater value node on left side *\/\r\n\tvoid delLesserNodes()\r\n\t{\r\n\t\t\/* 1.Reverse the linked list *\/\r\n\t\treverseList();\r\n\r\n\t\t\/* 2) In the reversed list, delete nodes which\r\n\t\thave a node with greater value node on left\r\n\t\tside. Note that head node is never deleted\r\n\t\tbecause it is the leftmost node.*\/\r\n\t\t_delLesserNodes();\r\n\r\n\t\t\/* 3) Reverse the linked list again to retain\r\n\t\tthe original order *\/\r\n\t\treverseList();\r\n\t}\r\n\r\n\t\/* Deletes nodes which have greater value node(s)on left side *\/\r\n\tvoid _delLesserNodes()\r\n\t{\r\n\t\tNode current = head;\r\n\r\n\t\tNode maxnode = head;\r\n\t\tNode temp;\r\n\r\n\t\twhile (current != null && current.next != null) {\r\n\t\t\t\/* If current is smaller than max, then delete\r\n\t\t\tcurrent *\/\r\n\t\t\tif (current.next.data < maxnode.data) {\r\n\t\t\t\ttemp = current.next;\r\n\t\t\t\tcurrent.next = temp.next;\r\n\t\t\t\ttemp = null;\r\n\t\t\t}\r\n\r\n\t\t\t\/* If current is greater than max, then update\tmax and move current *\/\r\n\t\t\telse {\r\n\t\t\t\tcurrent = current.next;\r\n\t\t\t\tmaxnode = current;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tvoid push(int new_data)\r\n\t{\r\n\t\r\n\t\tNode new_node = new Node(new_data);\r\n\t\r\n\t\tnew_node.next = head;\r\n\r\n\t\thead = new_node;\r\n\t}\r\n\r\n\tvoid reverseList()\r\n\t{\r\n\t\tNode current = head;\r\n\t\tNode prev = null;\r\n\t\tNode next;\r\n\t\twhile (current != null) {\r\n\t\t\tnext = current.next;\r\n\t\t\tcurrent.next = prev;\r\n\t\t\tprev = current;\r\n\t\t\tcurrent = next;\r\n\t\t}\r\n\t\thead = prev;\r\n\t}\r\n\tvoid printList()\r\n\t{\r\n\t\tNode temp = head;\r\n\t\twhile (temp != null) {\r\n\t\t\tSystem.out.print(temp.data + \" \");\r\n\t\t\ttemp = temp.next;\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n\tpublic static void main(String args[])\r\n\t{\r\n\t\tGreaterValue llist = new GreaterValue();\r\n\r\n\t\tllist.push(9);\r\n\t\tllist.push(2);\r\n\t\tllist.push(6);\r\n\t\tllist.push(5);\r\n\t\tllist.push(11);\r\n\t\tllist.push(5);\r\n\t\tllist.push(2);\r\n\t\tllist.push(12);\r\n\r\n\t\tSystem.out.println(\"Given Linked List\");\r\n\t\tllist.printList();\r\n\r\n\t\tllist.delLesserNodes();\r\n\r\n\t\tSystem.out.println(\"Modified Linked List\");\r\n\t\tllist.printList();\r\n\t}\r\n} \r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_3882_4\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"Python\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"Python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n\r\nclass Node:\r\n\tdef __init__(self, data):\r\n\t\tself.data = data\r\n\t\tself.next = None\r\n\r\nclass LinkedList:\r\n\r\n\tdef __init__(self):\r\n\t\tself.head = None\r\n\r\n\tdef push(self, new_data):\r\n\t\tnew_node = Node(new_data)\r\n\t\tnew_node.next = self.head\r\n\t\tself.head = new_node\r\n\r\n\tdef printList(self):\r\n\t\ttemp = self.head\r\n\t\twhile(temp):\r\n\t\t\tprint (temp.data,end=\" \")\r\n\t\t\ttemp = temp.next\r\n\r\n\tdef del_gr_right(self):\r\n\t\ti = self.head\r\n\t\t\r\n\t\twhile i:\r\n\t\t\tvalue = i.data\r\n\t\t\tfound = False\r\n\t\t\tj = i.next\r\n\t\t\t\r\n\t\t\twhile j:\r\n\t\t\t\tif j.data > value:\r\n\t\t\t\t\tfound = True\r\n\t\t\t\t\tbreak\r\n\t\t\t\tj = j.next\r\n\t\t\t\r\n\t\t\tif found:\r\n\t\t\t\ttemp = i.next\r\n\t\t\t\ti.data = i.next.data\r\n\t\t\t\ti.next = i.next.next\r\n\t\t\t\ttemp = None\r\n\t\t\telse:\r\n\t\t\t\ti = i.next\r\n\r\n\r\nllist = LinkedList()\r\nllist.push(11)\r\nllist.push(18)\r\nllist.push(20)\r\nllist.push(14)\r\nllist.push(15)\r\n\r\nprint (\"Given Linked List is:\")\r\nllist.printList()\r\nprint()\r\n\r\nllist.del_gr_right()\r\n\r\nprint (\"&#92;nLinked list after deletion is\")\r\nllist.printList()\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_3882 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_3882 a\"),jQuery(\"#tab-content_3882\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<h4>Output<\/h4>\n<p>15 14 20 18 11<br \/>\n20 18 11<\/p>\n<p><strong>Time complexity:<\/strong> O(N*N), due to 2 nested for loops.<br \/>\n<strong>Space complexity:<\/strong> O(1), as we don\u2019t use any extra space<br \/>\nHere, N is the total number of nodes in the given linked list.<\/p>\n<p>Can we do some improvements?<\/p>\n<p>If we could traverse from right to left, what improvements would it make?<\/p>\n<h3>Second Approach  to delete nodes having greater value on right: Reversing the linked list (optimized)<\/h3>\n<p>We can\u2019t traverse a linked list from right to left, let\u2019s reverse it.<\/p>\n<p>In the reversed linked list, we need to do the opposite. We have to remove all the nodes having greater value on the left. Since now, we can traverse from left to right, we can keep track of the maximum value and delete the node whose values are less than the maximum value till that node.<\/p>\n<p>After performing the required deletions, we can again reverse the linked list to get the result in the correct order.<\/p>\n<h3>Algorithm to delete nodes having greater value on right<\/h3>\n<ul>\n<li>Reverse the linked list.<\/li>\n<li>Now traverse the linked list and keep track of the maximum value.<\/li>\n<li>At any node, if the node\u2019s value is smaller than the maximum value till now, delete the node.<\/li>\n<li>Now we have a linked list in which all nodes having greater value on the left side have been deleted.<\/li>\n<li>Reverse the linked list and return it as our answer.<\/li>\n<\/ul>\n<h3>Dry Run to delete nodes having greater value on right,<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Delete-nodes-which-have-a-greater-value-on-right-side-2.png\" alt=\"\" \/><\/p>\n<h3>Code Implementation<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_3883 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_3883 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_3883 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_3883 .wpsm_nav-tabs > li.active > a, #tab_container_3883 .wpsm_nav-tabs > li.active > a:hover, #tab_container_3883 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_3883 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_3883 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_3883 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_3883 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_3883 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_3883 .wpsm_nav-tabs > li > a:hover , #tab_container_3883 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_3883 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_3883 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_3883 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_3883 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_3883 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_3883 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_3883 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_3883 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_3883 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_3883 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_3883 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_3883\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_3883\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_3883_1\" aria-controls=\"tabs_desc_3883_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_3883_2\" aria-controls=\"tabs_desc_3883_2\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C++<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_3883_3\" aria-controls=\"tabs_desc_3883_3\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Java<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_3883_4\" aria-controls=\"tabs_desc_3883_4\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Python<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_3883\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_3883_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"c\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n \r\n\/* structure of a linked list node *\/\r\nstruct Node {\r\n    int data;\r\n    struct Node* next;\r\n};\r\n \r\nvoid reverseList(struct Node** headref);\r\nvoid _delLesserNodes(struct Node* head);\r\nvoid delLesserNodes(struct Node** head_ref)\r\n{\r\n    reverseList(head_ref);\r\n \r\n    _delLesserNodes(*head_ref);\r\n \r\n    reverseList(head_ref);\r\n}\r\n \r\nvoid _delLesserNodes(struct Node* head)\r\n{\r\n    struct Node* current = head;\r\n \r\n    struct Node* maxnode = head;\r\n    struct Node* temp;\r\n \r\n    while (current != NULL && current->next != NULL) {\r\n        if (current->next->data < maxnode->data) {\r\n            temp = current->next;\r\n            current->next = temp->next;\r\n            free(temp);\r\n        }\r\n \r\n        else {\r\n            current = current->next;\r\n            maxnode = current;\r\n        }\r\n    }\r\n}\r\n \r\nvoid push(struct Node** head_ref, int new_data)\r\n{\r\n    struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));\r\n    new_node->data = new_data;\r\n    new_node->next = *head_ref;\r\n    *head_ref = new_node;\r\n}\r\nvoid reverseList(struct Node** headref)\r\n{\r\n    struct Node* current = *headref;\r\n    struct Node* prev = NULL;\r\n    struct Node* next;\r\n    while (current != NULL) {\r\n        next = current->next;\r\n        current->next = prev;\r\n        prev = current;\r\n        current = next;\r\n    }\r\n    *headref = prev;\r\n}\r\n \r\nvoid printList(struct Node* head)\r\n{\r\n    while (head != NULL) {\r\n        printf(\"%d \", head->data);\r\n        head = head->next;\r\n    }\r\n    printf(\"&#92;n\");\r\n}\r\nint main()\r\n{\r\n    struct Node* head = NULL;\r\n \r\n    push(&head, 3);\r\n    push(&head, 2);\r\n    push(&head, 6);\r\n    push(&head, 5);\r\n    push(&head, 11);\r\n    push(&head, 10);\r\n    push(&head, 15);\r\n    push(&head, 12);\r\n \r\n    printf(\"Given Linked List &#92;n\");\r\n    printList(head);\r\n \r\n    delLesserNodes(&head);\r\n \r\n    printf(\"Modified Linked List &#92;n\");\r\n    printList(head);\r\n \r\n    return 0;\r\n}\r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_3883_2\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"cpp\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include<bits stdc++.h>\r\nusing namespace std;\r\n\r\nstruct Node {\r\n    int val;\r\n    Node* next;\r\n\r\n    Node(int value){\r\n        val = value;\r\n        next = NULL;\r\n    }\r\n};\r\n\r\nvoid push_front(Node** head, int new_val){\r\n    Node* new_node = new Node(new_val);\r\n    new_node->next = *head;\r\n    *head = new_node;\r\n}\r\n\r\nvoid printList(Node* head){\r\n    Node* i = head;\r\n    while(i){\r\n        cout<<i->val<<\" \";\r\n        i = i->next;\r\n    }\r\n    cout<<\"&#92;n\";\r\n}\r\n\r\n\r\nNode* reverse_it(Node* head){\r\n    Node *prev = NULL;\r\n    Node *curr = head, *next;\r\n    while(curr!=NULL){\r\n        next = curr->next;\r\n        curr->next = prev;\r\n        prev = curr;\r\n        curr = next;\r\n    }\r\n    return prev;\r\n}\r\n\r\nvoid del_gr_right(Node** head){\r\n    \/\/ reverse the linked list\r\n    *head  = reverse_it(*head);\r\n\r\n    int mx = (*head)->val;\r\n    Node* prev = *head;\r\n     Node* curr = (*head)->next;\r\n\r\n    while(curr != NULL){\r\n        if(curr->val < mx){\r\n            \/\/ delete curr node\r\n            Node* temp = curr;\r\n            prev->next = curr->next;\r\n            curr = curr->next;\r\n            delete temp;\r\n        } else {\r\n            mx = max(mx, curr->val);\r\n            prev = curr;\r\n            curr = curr->next;\r\n        }\r\n    }\r\n    \/\/ once again reverse it\r\n    *head  = reverse_it(*head);\r\n}\r\n\r\nint main(){\r\n    Node* head = NULL;\r\n\r\n    push_front(&head, 11);\r\n    push_front(&head, 18);\r\n    push_front(&head, 20);\r\n    push_front(&head, 14);\r\n    push_front(&head, 15);\r\n\r\n    printList(head);\r\n    \/\/ 15 14 20 18 11\r\n\r\n    del_gr_right(&head);\r\n\r\n    printList(head);\r\n    \/\/ 20 18 11\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_3883_3\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"Java\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"Java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nclass Node {\r\n\t\r\n\tint data;\r\n\tNode next;\r\n\t\r\n\tpublic Node(int data){\r\n\t\tthis.data = data;\r\n\t\tthis.next = null;\r\n\t}\r\n}\r\n\r\nclass LLUtil{\r\n\t\r\n\tpublic Node createLL(int[] arr){\r\n\t\t\r\n\t\tNode head = new Node(arr[0]);\r\n\t\tNode temp = head;\r\n\t\t\r\n\t\tNode newNode = null;\r\n\t\tfor(int i = 1; i < arr.length; i++){\r\n\t\t\tnewNode = new Node(arr[i]);\r\n\t\t\ttemp.next = newNode;\r\n\t\t\ttemp = temp.next;\r\n\t\t}\r\n\t\treturn head;\r\n\t}\r\n\r\n\t\/\/This function prints given linked list\r\n\tpublic void printLL(Node head){\r\n\t\t\r\n\t\twhile(head != null){\r\n\t\t\tSystem.out.print(head.data + \" \");\r\n\t\t\thead = head.next;\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\r\n}\r\n\r\nclass GreaterValue {\r\n\tpublic static void main (String[] args) {\r\n\t\t\r\n\t\tint[] arr = {12,15,10,11,5,6,2,3};\r\n\t\tLLUtil llu = new LLUtil();\r\n\t\tNode head = llu.createLL(arr);\r\n\t\tSystem.out.println(\"Given Linked List\");\r\n\t\tllu.printLL(head);\r\n\t\thead = deleteNodesOnRightSide(head);\r\n\t\tSystem.out.println(\"Modified Linked List\");\r\n\t\tllu.printLL(head);\r\n\t\t\r\n\t}\r\n\tpublic static Node deleteNodesOnRightSide(Node head){\r\n\t\tif(head == null || head.next == null) return head;\r\n\t\tNode nextNode = deleteNodesOnRightSide(head.next);\r\n\r\n\t\tif(nextNode.data > head.data) return nextNode;\r\n\t\thead.next = nextNode;\r\n\r\n\t\treturn head;\r\n\t}\r\n}\r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_3883_4\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"Python\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"Python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nclass Node:\r\n\tdef __init__(self, data):\r\n\t\tself.data = data\r\n\t\tself.next = None\r\n\r\nclass LinkedList:\r\n\r\n\tdef __init__(self):\r\n\t\tself.head = None\r\n\r\n\tdef push(self, new_data):\r\n\t\tnew_node = Node(new_data)\r\n\t\tnew_node.next = self.head\r\n\t\tself.head = new_node\r\n\r\n\tdef printList(self):\r\n\t\ttemp = self.head\r\n\t\twhile(temp):\r\n\t\t\tprint (temp.data,end=\" \")\r\n\t\t\ttemp = temp.next\r\n\r\n\r\n\tdef reverse_it(self):\r\n\t\tprev = None\r\n\t\tcurr = self.head\r\n\r\n\t\twhile curr:\r\n\t\t\tnext = curr.next\r\n\t\t\tcurr.next = prev\r\n\t\t\tprev = curr\r\n\t\t\tcurr = next\r\n\r\n\t\tself.head = prev\r\n\r\n\t\treturn prev\r\n\r\n\tdef del_gr_right(self):\r\n\t\t\r\n\t\tself.reverse_it()\r\n\t\ttemp = self.head\r\n\t\tmx = self.head.data\r\n\t\tprev = self.head\r\n\t\tcurr = self.head.next\r\n\r\n\t\twhile curr:\r\n\t\t\tif curr.data < mx:\r\n\t\t\t\ttemp = curr\r\n\t\t\t\tprev.next = curr.next\r\n\t\t\t\tcurr = curr.next\r\n\t\t\t\tdel temp\r\n\t\t\telse:\r\n\t\t\t\tmx = max(mx, curr.data)\r\n\t\t\t\tprev = curr\r\n\t\t\t\tcurr = curr.next\r\n\r\n\t\tself.reverse_it()\r\n\r\n\r\n\r\nllist = LinkedList()\r\nllist.push(11)\r\nllist.push(18)\r\nllist.push(20)\r\nllist.push(14)\r\nllist.push(15)\r\n\r\nllist.printList()\r\n\r\nllist.del_gr_right()\r\n\r\nprint()\r\nllist.printList()\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_3883 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_3883 a\"),jQuery(\"#tab-content_3883\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<h4>Output<\/h4>\n<p>15 14 20 18 11<br \/>\n20 18 11<\/p>\n<p><strong>Time complexity:<\/strong> O(N), as we are traversing the linked list (three times).<\/p>\n<p>In this article, we have seen how to delete nodes that have a greater value on the right by two different approaches. All these concepts and approaches are good for strengthening your concepts in LinkedList and can help to prepare well for the interviews. If you want to get your hands on more on linked list , you can pratice from here<a href=\"https:\/\/mycode.prepbytes.com\/interview-coding\/practice\/linked-list\">Linked List<\/a>.<\/p>\n<table width=\"641\">\n<tbody>\n<tr>\n<td colspan=\"2\" width=\"641\" style=\"text-align: center\"><strong>Related Articles<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/doubly-circular-linked-list-introduction-and-insertion\/\">Doubly circular linked list in data structure<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/advantages-disadvantages-and-uses-of-a-doubly-linked-list\/\">Application of doubly linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/applications-of-linked-list-data-structure\/\">Applications of linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/difference-between-a-singly-linked-list-and-a-doubly-linked-list\/\">Singly linked list vs doubly linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/advantage-and-disadvantage-of-linked-list-over-array\/\">Advantages and disadvantages of linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/menu-driven-program-for-all-operations-on-doubly-linked-list-in-c\/\">Doubly linked list all operations in C<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/binary-search\/binary-search-on-linked-list\/\">Binary search in linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/bubble-sort-for-linked-list-by-swapping-nodes\/\">Bubble sort linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/delete-a-node-in-doubly-linked-list\/\">Deletion in doubly linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/delete-middle-of-linked-list\/\">Delete the middle node of a linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/adding-two-polynomials-using-linked-list\/\">Polynomial addition using linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/find-the-smallest-and-largest-elements-in-a-singly-linked-list\/\">Find max value and min value in linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/insert-a-node-at-a-specific-position-in-a-linked-list\/\">Insert a node at a specific position in a linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/swap-nodes-in-a-linked-list-without-swapping-data\/\">Swap nodes in linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/add-two-numbers-represented-by-linked-lists-set-1\/\">Add two numbers represented by linked lists<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/find-the-first-node-of-the-loop-in-a-linked-list\/\">Find starting point of loop in linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/merge-sort-on-a-singly-linked-list\/\">Merge sort linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/delete-a-node-at-a-given-position\/\">Delete a node from linked list at a given position<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/remove-duplicates-from-an-unsorted-linked-list\/\">Remove duplicates from unsorted linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/python\/python-program-to-reverse-a-linked-list\/\">Reverse a linked list in Python<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>FAQs<\/h2>\n<ol>\n<li><strong>Why is deletion easier in a doubly linked list?<\/strong><\/li>\n<p>In a singly linked list deletion requires a pointer to the node and also to delete the previous node but in a doubly linked list, it only requires deleting the pointer.<\/p>\n<li><strong>Is delete a keyword in java?<\/strong><\/li>\n<p>No delete is not a keyword in java.<\/p>\n<li><strong>What is the time complexity of deleting a node from the stack?<\/strong><\/li>\n<p>It requires O(n) time to delete the node from the stack.<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Introduction We can define a linked list as a sequence of data structures which are connected through links and each node is having a pointer which points to the next node. In this article, we will learn how to delete nodes which have a greater value on right side Problem Statement for delete nodes having [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[125],"tags":[],"class_list":["post-3880","post","type-post","status-publish","format-standard","hentry","category-linked-list"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Delete nodes that have a greater value on the right side | Linked list | Prepbytes<\/title>\n<meta name=\"description\" content=\"Learn to delete all the nodes from a linked list that have a greater valued node on the right side. This blog explains how to delete nodes that have a greater value on the right by two methods.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Delete nodes that have a greater value on the right side | Linked list | Prepbytes\" \/>\n<meta property=\"og:description\" content=\"Learn to delete all the nodes from a linked list that have a greater valued node on the right side. This blog explains how to delete nodes that have a greater value on the right by two methods.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-16T13:40:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-18T06:58:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186587688-delete%20nodes%20that%20have%20Greater%20Value%20On%20The%20Right%20Side_Artboard%206.png\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Delete nodes that have a greater value on the right side\",\"datePublished\":\"2021-08-16T13:40:42+00:00\",\"dateModified\":\"2022-11-18T06:58:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/\"},\"wordCount\":940,\"commentCount\":1,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186587688-delete%20nodes%20that%20have%20Greater%20Value%20On%20The%20Right%20Side_Artboard%206.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/\",\"name\":\"Delete nodes that have a greater value on the right side | Linked list | Prepbytes\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186587688-delete%20nodes%20that%20have%20Greater%20Value%20On%20The%20Right%20Side_Artboard%206.png\",\"datePublished\":\"2021-08-16T13:40:42+00:00\",\"dateModified\":\"2022-11-18T06:58:49+00:00\",\"description\":\"Learn to delete all the nodes from a linked list that have a greater valued node on the right side. This blog explains how to delete nodes that have a greater value on the right by two methods.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186587688-delete%20nodes%20that%20have%20Greater%20Value%20On%20The%20Right%20Side_Artboard%206.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186587688-delete%20nodes%20that%20have%20Greater%20Value%20On%20The%20Right%20Side_Artboard%206.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linked list articles\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/linked-list\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Delete nodes that have a greater value on the right side\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Delete nodes that have a greater value on the right side | Linked list | Prepbytes","description":"Learn to delete all the nodes from a linked list that have a greater valued node on the right side. This blog explains how to delete nodes that have a greater value on the right by two methods.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/","og_locale":"en_US","og_type":"article","og_title":"Delete nodes that have a greater value on the right side | Linked list | Prepbytes","og_description":"Learn to delete all the nodes from a linked list that have a greater valued node on the right side. This blog explains how to delete nodes that have a greater value on the right by two methods.","og_url":"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-08-16T13:40:42+00:00","article_modified_time":"2022-11-18T06:58:49+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186587688-delete%20nodes%20that%20have%20Greater%20Value%20On%20The%20Right%20Side_Artboard%206.png","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Delete nodes that have a greater value on the right side","datePublished":"2021-08-16T13:40:42+00:00","dateModified":"2022-11-18T06:58:49+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/"},"wordCount":940,"commentCount":1,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186587688-delete%20nodes%20that%20have%20Greater%20Value%20On%20The%20Right%20Side_Artboard%206.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/","url":"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/","name":"Delete nodes that have a greater value on the right side | Linked list | Prepbytes","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186587688-delete%20nodes%20that%20have%20Greater%20Value%20On%20The%20Right%20Side_Artboard%206.png","datePublished":"2021-08-16T13:40:42+00:00","dateModified":"2022-11-18T06:58:49+00:00","description":"Learn to delete all the nodes from a linked list that have a greater valued node on the right side. This blog explains how to delete nodes that have a greater value on the right by two methods.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186587688-delete%20nodes%20that%20have%20Greater%20Value%20On%20The%20Right%20Side_Artboard%206.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645186587688-delete%20nodes%20that%20have%20Greater%20Value%20On%20The%20Right%20Side_Artboard%206.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/delete-nodes-that-have-a-greater-value-on-the-right-side\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"Linked list articles","item":"https:\/\/prepbytes.com\/blog\/category\/linked-list\/"},{"@type":"ListItem","position":3,"name":"Delete nodes that have a greater value on the right side"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/3880","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=3880"}],"version-history":[{"count":8,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/3880\/revisions"}],"predecessor-version":[{"id":10568,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/3880\/revisions\/10568"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=3880"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=3880"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=3880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}