{"id":5818,"date":"2021-10-25T10:21:32","date_gmt":"2021-10-25T10:21:32","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=5818"},"modified":"2022-04-19T19:08:58","modified_gmt":"2022-04-19T19:08:58","slug":"given-a-linked-list-of-line-segments-remove-middle-points","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/","title":{"rendered":"Given a linked list of line segments, remove middle points"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012166470-Article_202.png\" alt=\"\" \/><\/p>\n<h3>Introduction<\/h3>\n<p>The linked list is one of the most important concepts to know while preparing for interviews. Having a good grasp of a linked list can be a huge plus point in coding interviews.<\/p>\n<\/p>\n<h3>Problem Statement<\/h3>\n<p>In this problem, we will be given a linked list, where each node will have two integers representing the x and y coordinates of a point. We need to remove the middle points present in the line segments drawn by joining the coordinates of the node.<\/p>\n<h3>Problem Statement Understanding<\/h3>\n<p>The problem statement is quite straightforward; we have to draw line segments corresponding to the coordinates of the nodes and then remove the middle points present in each line segment.<\/p>\n<p>Suppose we have a horizontal line segment formed by 6 different points, then according to the problem statement, we need to remove the four points in between the starting and ending point of the line segment and leave the starting and ending point as it is.<\/p>\n<ul>\n<li>We need to do the same with the lines that are vertical i.e., leave starting and ending points and remove middle points.<\/li>\n<\/ul>\n<p>Let&#8217;s try to understand the problem with the help of examples:<br \/>\nIf the linked list given to us is (4,3)\u2192(7,3)\u2192(10,3)\u2192(10,4)\u2192(10,7)\u2192(10,8)\u2192NULL.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/p_1-2.jpg\" alt=\"\" \/><\/p>\n<ul>\n<li>From the above graphical plot of the given linked list, we see that the first three nodes form a line segment parallel to the x-axis.<\/li>\n<li>So, the middle point in the line segment is the second node. Hence, it is removed.<\/li>\n<li>Similarly, the last three nodes form a line segment parallel to the y-axis and the last second node, and the last third node, are the points that lie in between the starting and ending point of the segment.<\/li>\n<li>Hence, both of them are removed from the list (removing middle points from line segment).<\/li>\n<li>So, after removing all the middle points from the linked list, our final resultant linked list will be: (4,3)\u2192(10,3)\u2192(10,8)\u2192NULL<\/li>\n<\/ul>\n<p>At this point, we have understood the problem statement. Now we will try to formulate an approach for this problem.<\/p>\n<p>Before moving to the approach section, try to think about how you can approach this problem.<\/p>\n<ul>\n<li>If stuck, no problem, we will thoroughly see how we can approach this problem in the next section.<\/li>\n<\/ul>\n<p>Let\u2019s move to the approach section.<\/p>\n<h3>Approach<\/h3>\n<ul>\n<li>We will maintain two pointers initialized by the first and second nodes of the given list, respectively.<\/li>\n<li>Now, we will iterate the list, and while iterating, we will check if two consecutive nodes have the same x or y coordinate or not.<\/li>\n<li>If that is the case, then we will remove all the nodes that have the same x or y coordinate as the first pointer and keep the second pointer at the end of the segment.<\/li>\n<li>In this way, all the middle points of the line segments will be removed, and hence our objective will be satisfied.<\/li>\n<\/ul>\n<p>The approach is discussed in more depth in the algorithm section.<\/p>\n<h3>Algorithm<\/h3>\n<p>1) Initialize two pointers <strong>prev<\/strong> and <strong>curr<\/strong> with the first and second node of the list, respectively.<br \/>\n2) Iterate the list till <strong>curr<\/strong> is not NULL.<br \/>\n3) If the x-coordinate of <strong>curr<\/strong>, as well as <strong>prev<\/strong>, is equal (i.e., vertical line), then:<br \/>\na) Create a <strong>start<\/strong> variable initialized to <strong>prev<\/strong>, which will denote the starting of the segment.<br \/>\nb) Move <strong>prev<\/strong> and <strong>curr<\/strong> forward by one node<br \/>\nc) Now, run a while loop until <strong>curr<\/strong> is not NULL and x-coordinates of <strong>curr<\/strong> and <strong>prev<\/strong> are equal.<br \/>\nd) Inside the loop, attach <strong>curr<\/strong> after <strong>start<\/strong> and delete the <strong>prev<\/strong> node.<br \/>\ne) Also, update <strong>prev<\/strong> to <strong>curr<\/strong> and move <strong>curr<\/strong> forward by one node.<br \/>\n4) If the y-coordinate of <strong>curr<\/strong>, as well as <strong>prev<\/strong>, is equal (i.e., Horizontal line), then:<br \/>\na) Create a <strong>start<\/strong> variable initialized to <strong>prev<\/strong>, which will denote starting of the segment.<br \/>\nb) Move <strong>prev<\/strong> and <strong>curr<\/strong> forward by one node.<br \/>\nc) Now, run a while loop until <strong>curr<\/strong> is not NULL and y-coordinates of <strong>curr<\/strong> and <strong>prev<\/strong> are equal.<br \/>\nd) Inside the loop, attach <strong>curr<\/strong> after <strong>start<\/strong> and delete the <strong>prev<\/strong> node.<br \/>\ne) Also, update <strong>prev<\/strong> to <strong>curr<\/strong> and move <strong>curr<\/strong> forward by one node.<br \/>\n5) If none of the two coordinates is equal, move forward <strong>prev<\/strong> and <strong>curr<\/strong> by one node.<\/p>\n<h3>Dry Run<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/p_2-2.jpg\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/p_3-1.jpg\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/p_4.jpg\" 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_5819 {\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_5819 .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_5819 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_5819 .wpsm_nav-tabs > li.active > a, #tab_container_5819 .wpsm_nav-tabs > li.active > a:hover, #tab_container_5819 .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_5819 .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_5819 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_5819 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_5819 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_5819 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_5819 .wpsm_nav-tabs > li > a:hover , #tab_container_5819 .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_5819 .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_5819 .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_5819 .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_5819 .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_5819 .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_5819 .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_5819 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5819 .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_5819 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5819 .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_5819 .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_5819\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_5819\">\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_5819_1\" aria-controls=\"tabs_desc_5819_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_5819_2\" aria-controls=\"tabs_desc_5819_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_5819_3\" aria-controls=\"tabs_desc_5819_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_5819_4\" aria-controls=\"tabs_desc_5819_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_5819\">\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_5819_1\">\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 <iostream>\r\nusing namespace std;\r\n\r\nclass Node {\r\n    public:\r\n    int x, y;\r\n    Node *next;\r\n    \/\/constructor\r\n    Node(int x,int y){\r\n        this->x = x;\r\n        this->y = y;\r\n        next = NULL;\r\n    }\r\n};\r\n\r\n\/\/ Using this function we will print the list\r\nvoid printList(Node *head)\r\n{\r\n    Node *temp = head;    \r\n    while (temp != NULL) {\r\n        printf(\"(%d, %d)-> \", temp->x, temp->y);        \r\n        temp = temp->next;\r\n    }    \r\n    printf(\"NULL&#92;n\");\r\n}\r\n\r\n\/\/ Using these functions we will delete the middle nodes from the given linked list.\r\nvoid delete_Middle_Nodes(Node *head)\r\n{    \r\n    Node *curr = head->next, *prev = head;\r\n    \r\n    while (curr) {\r\n        \r\n        \/\/ x-coordinate equality check\r\n        if (curr->x == prev->x)\r\n        {\r\n            Node *start = prev;\r\n            prev = curr;\r\n            curr = curr->next;        \r\n            \r\n            \/\/remove the nodes in middle of\r\n            \/\/the segment parallel to y-axis\r\n            while (curr && curr->x == prev->x)\r\n            {\r\n                start->next = curr;\r\n                free(prev);\r\n                prev = curr;\r\n                curr = curr->next;\r\n            }\r\n        }\r\n\r\n        \/\/ y-coordinate equality check\r\n        else if (curr->y == prev->y)\r\n        {\r\n            Node *start = prev;\r\n            prev = curr;\r\n            curr = curr->next;\r\n            \r\n            \/\/remove the nodes in middle of\r\n            \/\/the segment parallel to x-axis\r\n            while (curr && curr->y == prev->y)\r\n            {\r\n                start->next = curr;\r\n                free(prev);\r\n                prev = curr;\r\n                curr = curr->next;\r\n            }\r\n        } else {\r\n            prev = curr;\r\n            curr = curr->next;\r\n        }\r\n    }\r\n}\r\n\r\nint main() {\r\n    Node *head = NULL;\r\n    head = new Node(4,3);\r\n    head->next = new Node(7,3);\r\n    head->next->next = new Node(10,3);\r\n    head->next->next->next = new Node(10,4);\r\n    head->next->next->next->next = new Node(10,7);\r\n    head->next->next->next->next->next = new Node(10,8);\r\n    \r\n    printf(\"Given Linked List: &#92;n\");\r\n    printList(head);\r\n    \r\n    delete_Middle_Nodes(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<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\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_5819_2\">\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\nstruct Node\r\n{\r\n    int x, y;\r\n    struct Node *next;\r\n};\r\n \r\nvoid push(struct Node ** head_ref, int x,int y)\r\n{\r\n    struct Node* new_node =\r\n           (struct Node*) malloc(sizeof(struct Node));\r\n    new_node->x  = x;\r\n    new_node->y  = y;\r\n    new_node->next = (*head_ref);\r\n    (*head_ref)  = new_node;\r\n}\r\n \r\nvoid printList(struct Node *head)\r\n{\r\n    struct Node *temp = head;\r\n    while (temp != NULL)\r\n    {\r\n        printf(\"(%d,%d)-> \", temp->x,temp->y);\r\n        temp = temp->next;\r\n    }\r\n    printf(\"&#92;n\");\r\n \r\n}\r\n \r\nvoid deleteNode(struct Node *head, struct Node *Next)\r\n{\r\n    head->next = Next->next;\r\n    Next->next = NULL;\r\n    free(Next);\r\n}\r\n \r\nstruct Node* deleteMiddle(struct Node *head)\r\n{\r\n    \/\/ If only one node or no node...Return back\r\n    if (head==NULL || head->next ==NULL || head->next->next==NULL)\r\n        return head;\r\n \r\n    struct Node* Next = head->next;\r\n    struct Node *NextNext = Next->next ;\r\n \r\n    \/\/ Check if this is a vertical line or horizontal line\r\n    if (head->x == Next->x)\r\n    {\r\n        \/\/ Find middle nodes with same x value, and delete them\r\n        while (NextNext !=NULL && Next->x==NextNext->x)\r\n        {\r\n            deleteNode(head, Next);\r\n \r\n            \/\/ Update Next and NextNext for next iteration\r\n            Next = NextNext;\r\n            NextNext = NextNext->next;\r\n        }\r\n    }\r\n    else if (head->y==Next->y) \/\/ If horizontal line\r\n    {\r\n        \/\/ Find middle nodes with same y value, and delete them\r\n        while (NextNext !=NULL && Next->y==NextNext->y)\r\n        {\r\n            deleteNode(head, Next);\r\n \r\n            \/\/ Update Next and NextNext for next iteration\r\n            Next = NextNext;\r\n            NextNext = NextNext->next;\r\n        }\r\n    }\r\n    else  \/\/ Adjacent points must have either same x or same y\r\n    {\r\n        puts(\"Given linked list is not valid\");\r\n        return NULL;\r\n    }\r\n \r\n    \/\/ Recur for next segment\r\n    deleteMiddle(head->next);\r\n \r\n    return head;\r\n}\r\n \r\n\/\/ Driver program to test above functions\r\nint main()\r\n{\r\n    struct Node *head = NULL;\r\n \r\n    push(&head, 40,5);\r\n    push(&head, 20,5);\r\n    push(&head, 10,5);\r\n    push(&head, 10,8);\r\n    push(&head, 10,10);\r\n    push(&head, 3,10);\r\n    push(&head, 1,10);\r\n    push(&head, 0,10);\r\n    printf(\"Given Linked List: &#92;n\");\r\n    printList(head);\r\n \r\n    if (deleteMiddle(head) != NULL);\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_5819_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 LineSegment\r\n{\r\n\tNode head; \r\n\tclass Node\r\n\t{\r\n\t\tint x,y;\r\n\t\tNode next;\r\n\t\tNode(int x, int y)\r\n\t\t{\r\n\t\t\tthis.x = x;\r\n\t\t\tthis.y = y;\r\n\t\t\tnext = null;\r\n\t\t}\r\n\t}\r\n\r\n\t\/* This function deletes middle nodes in a sequence of\r\n\t horizontal and vertical line segments represented\r\n\t by linked list. *\/\r\n\tNode deleteMiddle()\r\n\t{\r\n\t\t\/\/ If only one node or no node...Return back\r\n\t\tif (head == null || head.next == null ||\r\n\t\t\thead.next.next == null)\r\n\t\t\treturn head;\r\n\r\n\t\tNode Next = head.next;\r\n\t\tNode NextNext = Next.next;\r\n\r\n\t\t\/\/ check if this is vertical or horizontal line\r\n\t\tif (head.x == Next.x)\r\n\t\t{\r\n\t\t\t\/\/ Find middle nodes with same value as x and\r\n\t\t\t\/\/ delete them.\r\n\t\t\twhile (NextNext != null && Next.x == NextNext.x)\r\n\t\t\t{\r\n\t\t\t\thead.next = Next.next;\r\n\t\t\t\tNext.next = null;\r\n\r\n\t\t\t\t\/\/ Update NextNext for the next iteration\r\n\t\t\t\tNext = NextNext;\r\n\t\t\t\tNextNext = NextNext.next;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t\/\/ if horizontal\r\n\t\telse if (head.y == Next.y)\r\n\t\t{\r\n\t\t\t\/\/ find middle nodes with same value as y and\r\n\t\t\t\/\/ delete them\r\n\t\t\twhile (NextNext != null && Next.y == NextNext.y)\r\n\t\t\t{\r\n\t\t\t\thead.next = Next.next;\r\n\t\t\t\tNext.next = null;\r\n\r\n\t\t\t\t\/\/ Update NextNext for the next iteration\r\n\t\t\t\tNext = NextNext;\r\n\t\t\t\tNextNext = NextNext.next;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\/\/ Adjacent points should have same x or same y\r\n\t\telse\r\n\t\t{\r\n\t\t\tSystem.out.println(\"Given list is not valid\");\r\n\t\t\treturn null;\r\n        }\r\n\t\t\/\/ temporarily store the head and move head forward.\r\n\t\tNode temp = head;\r\n\t\thead = head.next;\r\n\r\n\t\t\/\/ call deleteMiddle() for next segment\r\n\t\tthis.deleteMiddle();\r\n\r\n\t\t\/\/ restore head\r\n\t\thead = temp;\r\n\t\treturn head;\r\n\t}\r\n\tvoid push(int x, int y)\r\n\t{\r\n\t\tNode new_node = new Node(x,y);\r\n\t\tnew_node.next = head;\r\n\t\thead = new_node;\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{\r\n\t\t\tSystem.out.print(\"(\"+temp.x+\",\"+temp.y+\")->\");\r\n\t\t\ttemp = temp.next;\r\n\t\t}\r\n\t\tSystem.out.println(\"NULL\");\r\n\t}\r\n\r\n\r\n\t\/* Driver program to test above functions *\/\r\n\tpublic static void main(String args[])\r\n\t{\r\n\t\tLineSegment llist = new LineSegment();\r\n\r\n\t\tllist.push(4,3);\r\n\t\tllist.push(7,3);\r\n\t\tllist.push(10,3);\r\n\t\tllist.push(10,4);\r\n\t\tllist.push(10,7);\r\n\t\tllist.push(10,8);\r\n\t\t\r\n\t\tSystem.out.println(\"Given list\");\r\n\t\tllist.printList();\r\n\r\n\t\tif (llist.deleteMiddle() != null)\r\n\t\t{\r\n\t\t\tSystem.out.println(\"Modified Linked List is\");\r\n\t\t\tllist.printList();\r\n\t\t}\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_5819_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 LinkedList(object):\r\n\tdef __init__(self):\r\n\t\tself.head = None\r\n\r\n\tclass Node(object):\r\n\t\tdef __init__(self, x, y):\r\n\t\t\tself.x = x\r\n\t\t\tself.y = y\r\n\t\t\tself.next = None\r\n\r\n\tdef deleteMiddle(self):\r\n\t\tcurr = self.head.next\r\n\t\tprev = self.head\r\n\t\twhile curr:\r\n\r\n\t\t\tif curr.x == prev.x:\r\n\r\n\t\t\t\tstart = prev\r\n\t\t\t\tprev = curr\r\n\t\t\t\tcurr = curr.next\r\n\r\n\t\t\t\twhile curr and curr.x == prev.x:\r\n\t\t\t\t\tstart.next = curr\r\n\t\t\t\t\tdel prev\r\n\t\t\t\t\tprev = curr\r\n\t\t\t\t\tcurr = curr.next\r\n\r\n\t\t\telif curr.y == prev.y:\r\n\r\n\t\t\t\tstart = prev\r\n\t\t\t\tprev = curr\r\n\t\t\t\tcurr = curr.next\r\n\r\n\t\t\t\twhile curr and curr.y == prev.y:\r\n\t\t\t\t\tstart.next = curr\r\n\t\t\t\t\tdel prev\r\n\t\t\t\t\tprev = curr\r\n\t\t\t\t\tcurr = curr.next\r\n\r\n\t\t\telse:\r\n\t\t\t\tprev = curr\r\n\t\t\t\tcurr = curr.next\r\n\r\n\r\n\r\n\tdef push(self, x, y):\r\n\r\n\t\tnew_node = self.Node(x, y)\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 != None:\r\n\t\t\tprint (\"(\" + str(temp.x) + \",\" + str(temp.y) + \")->\",end=\" \")\r\n\t\t\ttemp = temp.next\r\n\t\tprint (\"Null\")\r\n\r\n# Driver program\r\nllist = LinkedList()\r\nllist.push(10,8)\r\nllist.push(10,7)\r\nllist.push(10,4)\r\nllist.push(10,3)\r\nllist.push(7,3)\r\nllist.push(4,3)\r\n\r\nprint (\"Given list\")\r\nllist.printList()\r\n\r\nllist.deleteMiddle()\r\nprint (\"Modified Linked List is\")\r\nllist.printList()\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\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_5819 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_5819 a\"),jQuery(\"#tab-content_5819\"));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>Given Linked List:<br \/>\n(4, 3)-&gt; (7, 3)-&gt; (10, 3)-&gt; (10, 4)-&gt; (10, 7)-&gt; (10, 8)-&gt; NULL<br \/>\nModified Linked List:<br \/>\n(4, 3)-&gt; (10, 3)-&gt; (10, 8)-&gt; NULL<\/p>\n<p><strong>Time Complexity:<\/strong> O(n), n is the number of nodes in the given list.<br \/>\n[forminator_quiz id=&#8221;5820&#8243;]<\/p>\n<p>So, in this blog, we have tried to explain how you can remove middle points from a linked list where each node represents a coordinate in the XY-plane in the most optimal way. If you want to solve more questions on Linked List, which are curated by our expert mentors at PrepBytes, you can follow this link <a href=\"https:\/\/mycode.prepbytes.com\/interview-coding\/practice\/linked-list\">Linked List<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction The linked list is one of the most important concepts to know while preparing for interviews. Having a good grasp of a linked list can be a huge plus point in coding interviews. Problem Statement In this problem, we will be given a linked list, where each node will have two integers representing the [&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-5818","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>Given a linked list of line segments, remove middle points | Linked List | Prepbytes<\/title>\n<meta name=\"description\" content=\"Learn how to remove middle points in a linked list of line segments.\" \/>\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\/given-a-linked-list-of-line-segments-remove-middle-points\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Given a linked list of line segments, remove middle points | Linked List | Prepbytes\" \/>\n<meta property=\"og:description\" content=\"Learn how to remove middle points in a linked list of line segments.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/\" \/>\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-10-25T10:21:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-19T19:08:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012166470-Article_202.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=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Given a linked list of line segments, remove middle points\",\"datePublished\":\"2021-10-25T10:21:32+00:00\",\"dateModified\":\"2022-04-19T19:08:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/\"},\"wordCount\":820,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012166470-Article_202.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/\",\"name\":\"Given a linked list of line segments, remove middle points | Linked List | Prepbytes\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012166470-Article_202.png\",\"datePublished\":\"2021-10-25T10:21:32+00:00\",\"dateModified\":\"2022-04-19T19:08:58+00:00\",\"description\":\"Learn how to remove middle points in a linked list of line segments.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012166470-Article_202.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012166470-Article_202.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/#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\":\"Given a linked list of line segments, remove middle points\"}]},{\"@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":"Given a linked list of line segments, remove middle points | Linked List | Prepbytes","description":"Learn how to remove middle points in a linked list of line segments.","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\/given-a-linked-list-of-line-segments-remove-middle-points\/","og_locale":"en_US","og_type":"article","og_title":"Given a linked list of line segments, remove middle points | Linked List | Prepbytes","og_description":"Learn how to remove middle points in a linked list of line segments.","og_url":"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-10-25T10:21:32+00:00","article_modified_time":"2022-04-19T19:08:58+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012166470-Article_202.png","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Given a linked list of line segments, remove middle points","datePublished":"2021-10-25T10:21:32+00:00","dateModified":"2022-04-19T19:08:58+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/"},"wordCount":820,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012166470-Article_202.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/","url":"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/","name":"Given a linked list of line segments, remove middle points | Linked List | Prepbytes","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012166470-Article_202.png","datePublished":"2021-10-25T10:21:32+00:00","dateModified":"2022-04-19T19:08:58+00:00","description":"Learn how to remove middle points in a linked list of line segments.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012166470-Article_202.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012166470-Article_202.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/given-a-linked-list-of-line-segments-remove-middle-points\/#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":"Given a linked list of line segments, remove middle points"}]},{"@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\/5818","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=5818"}],"version-history":[{"count":5,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5818\/revisions"}],"predecessor-version":[{"id":7923,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5818\/revisions\/7923"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=5818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=5818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=5818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}