{"id":3859,"date":"2021-08-16T12:50:24","date_gmt":"2021-08-16T12:50:24","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=3859"},"modified":"2022-03-08T12:37:15","modified_gmt":"2022-03-08T12:37:15","slug":"remove-nth-node-from-end-of-the-linked-list","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/","title":{"rendered":"Remove Nth Node From End Of The Linked List"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644925925236-105.Remove%20Nth%20Node%20from_Artboard%206.png\" alt=\"\" \/><\/p>\n<h3>Problem Statement<\/h3>\n<p>Given a singly linked list along with a positive integer N. Write a function to delete the N<sup>th<\/sup> node from the end of the given linked list.<\/p>\n<\/p>\n<h3>Problem Statement Understanding<\/h3>\n<p>Let&#8217;s understand the given problem with the help of some examples:<\/p>\n<p>If our initial linked list:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-1.png\" alt=\"\" \/><\/p>\n<p>It means that here we had to remove the N = 3<sup>rd<\/sup> node from the end which is 3, so we will remove it.<\/p>\n<p>After removing the 3<sup>rd<\/sup> node from the end of the linked list, our output resultant linked list is <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/resultant-linked-list-1.png\" alt=\"\" \/><\/p>\n<p>If our initial linked list:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-2.png\" alt=\"\" \/><\/p>\n<p>It means that here we had to remove the N=1<sup>st<\/sup> node from the end which is 6, so we will remove it.<\/p>\n<p>After removing the 1<sup>st<\/sup> node from the end of the linked list, our output resultant linked list is:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/resultant-linked-list-2.png\" alt=\"\" \/><\/p>\n<p>I hope that now you have understood this problem. Now, think of how we can approach this problem?<\/p>\n<p>One simple approach will be to first find the length of linked list and then using it find the Nth node from the end. Let\u2019s see how we will do this.<\/p>\n<p>If length of our linked list is P, it means that we have to find (P-N)<sup>th<\/sup> node from the beginning of the linked list and this node will be the N<sup>th<\/sup> node from the end of the linked list.<\/p>\n<p>So to delete N<sup>th<\/sup> node using the above approach we will have to first traverse the linked list and find the length P of the linked list. Then we will have to again traverse the linked list (P-N+1) steps to reach the N<sup>th<\/sup> node from the end. <\/p>\n<p>This will work fine, but it is taking 2 traversals of linked list to find the N<sup>th<\/sup> node from the end. Now try to think, do we actually require the length of linked list to find the N<sup>th<\/sup> node from the end of the linked list?<\/p>\n<p>So in approach we will see how we can do it in single traversal of linked list.<\/p>\n<h3>Approach<\/h3>\n<p>Our approach would be simple.<br \/>\nTo remove the N<sup>th<\/sup> node from the end, we need two things, which are:<br \/>\n1) the N<sup>th<\/sup> node from the end and<br \/>\n2) the node just before it.<\/p>\n<p>First, we need to find the N<sup>th<\/sup> node from the end of the linked list. There are many ways to do so. We will use the most efficient one, i.e., using 2 pointers.<\/p>\n<p>We start with 2 pointers from the head. <\/p>\n<ul>\n<li>Move one of them to the N<sup>th<\/sup> node.<\/li>\n<li>Now, both pointers are N nodes apart. If we move them forward together, that distance will be maintained.<\/li>\n<li>Now, move both the pointers together till the forward pointer points to the last node. <\/li>\n<li>Now, the backward pointer is N nodes far from the forward node. So, it will point to the nth node from the end. That is our required node to delete, so we delete it.<\/li>\n<\/ul>\n<p>Think of some cases that we have to take care of while performing this operation, also try to implement the approach yourself.<\/p>\n<p>Below is the step-by-step algorithm for the above approach.<\/p>\n<h3>Algorithm<\/h3>\n<ul>\n<li>Initialize 2 pointers <em>i<\/em> and <em>j<\/em> pointing to head node.<\/li>\n<li>Move the pointer <em>j<\/em>, N steps ahead.<\/li>\n<li>If we reach the end before reaching the N<sup>th<\/sup> node, this means N is greater than the length of the linked list (N<sup>th<\/sup> node doesn\u2019t exist). So, we simply stop and return. <\/li>\n<li>Else declare a prev pointer to keep track of the node just before the node pointed by <em>i<\/em>.<\/li>\n<li>Now move both the pointers, <em>i<\/em> and <em>j<\/em>, together(along with the prev pointe) till <em>j<\/em> reaches the end node.<\/li>\n<li>Now, <em>i<\/em> will be pointing to the N<sup>th<\/sup> node from the end.<\/li>\n<li>Now we have to remove it from the linked list.<\/li>\n<li>First, we simply disconnect the i<sup>th<\/sup> node from the linked list by doing <strong>prev-&gt;next = i-&gt;next<\/strong>.<\/li>\n<li>If the node to remove is the first node, we need to modify the head pointer as well.<\/li>\n<li>At the end, delete <em>i<\/em>.<\/li>\n<\/ul>\n<h3>Dry Run<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Remove-Nth-node-from-end-of-the-linked-list.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_3860 {\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_3860 .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_3860 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_3860 .wpsm_nav-tabs > li.active > a, #tab_container_3860 .wpsm_nav-tabs > li.active > a:hover, #tab_container_3860 .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_3860 .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_3860 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_3860 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_3860 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_3860 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_3860 .wpsm_nav-tabs > li > a:hover , #tab_container_3860 .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_3860 .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_3860 .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_3860 .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_3860 .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_3860 .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_3860 .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_3860 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_3860 .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_3860 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_3860 .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_3860 .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_3860\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_3860\">\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_3860_1\" aria-controls=\"tabs_desc_3860_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_3860_2\" aria-controls=\"tabs_desc_3860_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_3860_3\" aria-controls=\"tabs_desc_3860_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_3860_4\" aria-controls=\"tabs_desc_3860_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_3860\">\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_3860_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\nstruct Node\r\n{\r\n    int data;\r\n    struct Node* next;\r\n};\r\n\r\n\/\/ since we are \r\nvoid insert_at_begenning ( struct Node **head_pointer, int data)\r\n{\r\n    \/\/ allocate memory for new node\r\n    struct Node *temp_node = (struct Node*) malloc(sizeof(struct Node));\r\n\r\n    \/\/ assign the data to new node\r\n    temp_node->data = data;\r\n\r\n    \/\/ initialize the new node to point to NULL\r\n    temp_node->next = NULL;\r\n\r\n    \/\/ if this is the first pointer, then this is the head pointer\r\n    if (*head_pointer == NULL)\r\n    {\r\n        *head_pointer = temp_node;\r\n    }\r\n    else\r\n    {\r\n        \/\/ point the next of the present pointer to the head pointer\r\n        temp_node->next = *head_pointer;\r\n\r\n        \/\/then move the reference of head pointer to the current pointer\r\n        *head_pointer = temp_node;\r\n    }\r\n}\r\n\r\nvoid display_list(struct Node **head_pointer)\r\n{\r\n    \/\/ take a reference to head pointer for navigation\r\n    struct Node *temp = *head_pointer;\r\n\r\n    while(temp != NULL)\r\n    {\r\n        if(temp->next != NULL)\r\n            printf(\"%d -> \", temp->data);\r\n        else\r\n            printf(\"%d\", temp->data);\r\n\r\n        \/\/navigate to next pointer\r\n        temp = temp->next;\r\n    }\r\n    printf(\"&#92;n\");\r\n}\r\nstruct Node * delete_node_from_end(struct Node *head, int num)\r\n{\r\n\r\n    \/\/ initialize both slow_pointer and fast_pointer pointing to head pointer\r\n    struct Node *slow_pointer = head, *fast_pointer = head;\r\n\r\n    \/\/ move fast pointer num steps ahead\r\n    for (int i = 0; i < num; i++)\r\n        fast_pointer = fast_pointer->next;\r\n\r\n    \/\/ while fast_pointer is not null, increment both pointers one step at a time\r\n    while (fast_pointer->next) \r\n    {\r\n        fast_pointer = fast_pointer->next;\r\n        slow_pointer = slow_pointer->next;\r\n    }\r\n\r\n    \/\/ once we get the node to be deleted, get that node, \r\n    \/\/      store it in a local variable. This is because, it can be deleted later\r\n    struct Node *node_to_be_deleted = slow_pointer->next;\r\n\r\n    \/\/ link the slow pointer point to the next element\r\n    slow_pointer->next = slow_pointer->next->next;\r\n    \r\n    \/\/ free the memory allocated for that pointer\r\n    free(node_to_be_deleted);\r\n\r\n    return head;\r\n}\r\n\r\n\r\nint main()\r\n{\r\n    struct Node *head = NULL; \r\n\r\n    insert_at_begenning(&head,80);\r\n    insert_at_begenning(&head,70);\r\n    insert_at_begenning(&head,60);\r\n    insert_at_begenning(&head,50);\r\n    insert_at_begenning(&head,40);\r\n    insert_at_begenning(&head,30);\r\n    insert_at_begenning(&head,20);\r\n    insert_at_begenning(&head,10);\r\n\r\n    printf(\"The present linked list is&#92;n\");\r\n    display_list(&head);\r\n\r\n    head = delete_node_from_end(head, 2);\r\n    printf(\"The linked list after deleting 2nd element from end is  is&#92;n\");\r\n    display_list(&head);\r\n\r\n    return 0;\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_3860_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 remove_nth_node_from_end(Node** head, int n){\r\n    Node *i, *j;\r\n    i = j = *head;\r\n\r\n    n--;\r\n    \/\/ move j n steps ahead\r\n    while(n>0 && j->next!=NULL){\r\n        j = j->next;\r\n        n--;\r\n    }\r\n\r\n    if(n!=0){\r\n        cout<<\"n is either <= 0 or larger than the linked list size&#92;n\";\r\n        return;\r\n    }\r\n\r\n    \/\/ move i and j together till j reaches the end\r\n    Node *prev = i;\r\n    while(j->next!=NULL){\r\n        prev = i;\r\n        i = i->next;\r\n        j = j->next;\r\n    }\r\n\r\n    \/\/ now i will point to the nth node from end\r\n    \/\/ remove it\r\n    prev->next = i->next;\r\n\r\n    \/\/ if i points to first node\r\n    \/\/ modify the head pointer as well\r\n    if(i == *head){\r\n        *head = i->next;\r\n    }\r\n    delete i;\r\n}\r\n\r\n\r\nint main(){\r\n    Node* head = NULL;\r\n\r\n    push_front(&head, 5);\r\n    push_front(&head, 4);\r\n    push_front(&head, 3);\r\n    push_front(&head, 2);\r\n    push_front(&head, 1);\r\n\r\n    printList(head);\r\n    \/\/ 1 2 3 4 5\r\n    \r\n    \/\/ to remove 3rd node from end\r\n    remove_nth_node_from_end(&head, 3);\r\n\r\n    printList(head);\r\n    \/\/ 1 2 4 5\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_3860_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 RemoveEnd \r\n{\r\n\tNode head;\r\n\tclass Node \r\n    {\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\t\/\/ Function to delete the nth node from\r\n\t\/\/ the end of the given linked list\r\n\tvoid deleteNode(int key)\r\n\t{\r\n\r\n\t\t\/\/ First pointer will point to\r\n\t\t\/\/ the head of the linked list\r\n\t\tNode first = head;\r\n\r\n\t\t\/\/ Second pointer will point to the\r\n\t\t\/\/ Nth node from the beginning\r\n\t\tNode second = head;\r\n\t\tfor (int i = 0; i < key; i++) {\r\n\r\n\t\t\t\/\/ If count of nodes in the given\r\n\t\t\t\/\/ linked list is <= N\r\n\t\t\tif (second.next == null) {\r\n\r\n\t\t\t\t\/\/ If count = N i.e. delete the head node\r\n\t\t\t\tif (i == key - 1)\r\n\t\t\t\t\thead = head.next;\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tsecond = second.next;\r\n\t\t}\r\n\t\t\/\/ Increment both the pointers by one until\r\n\t\t\/\/ second pointer reaches the end\r\n\t\twhile (second.next != null) {\r\n\t\t\tfirst = first.next;\r\n\t\t\tsecond = second.next;\r\n\t\t}\r\n\t\t\/\/ First must be pointing to the\r\n\t\t\/\/ Nth node from the end by now\r\n\t\t\/\/ So, delete the node first is pointing to\r\n\t\tfirst.next = first.next.next;\r\n\t}\r\n\tpublic void push(int new_data)\r\n\t{\r\n\t\tNode new_node = new Node(new_data);\r\n\t\tnew_node.next = head;\r\n\t\thead = new_node;\r\n\t}\r\n\tpublic void printList()\r\n\t{\r\n\t\tNode tnode = head;\r\n\t\twhile (tnode != null) {\r\n\t\t\tSystem.out.print(tnode.data + \" \");\r\n\t\t\ttnode = tnode.next;\r\n\t\t}\r\n\t}\r\n\tpublic static void main(String[] args)\r\n\t{\r\n\t\tRemoveEnd llist = new RemoveEnd();\r\n\r\n\t\tllist.push(7);\r\n\t\tllist.push(1);\r\n\t\tllist.push(3);\r\n\t\tllist.push(2);\r\n\r\n\t\tSystem.out.println(\"&#92;nCreated Linked list is:\");\r\n\t\tllist.printList();\r\n\r\n\t\tint N = 1;\r\n\t\tllist.deleteNode(N);\r\n\r\n\t\tSystem.out.println(\"&#92;nLinked List after Deletion is:\");\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_3860_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\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 create(self, x):\r\n\r\n\t\tnew_node = Node(x)\r\n\r\n\t\tif self.head is None:\r\n\t\t\tself.head = new_node\r\n\t\t\treturn\r\n\r\n\t\tlast = self.head\r\n\t\twhile last.next:\r\n\t\t\tlast = last.next\r\n\r\n\t\tlast.next = new_node\r\n\r\n\tdef display(self):\r\n\t\ttemp = self.head\r\n\r\n\t\twhile temp:\r\n\t\t\tprint(temp.data, end = \" \")\r\n\t\t\ttemp = temp.next\r\n\r\ndef removeNthFromEnd(head, k):\r\n\t\r\n\tfirst = head\r\n\tsecond = head\r\n\tcount = 1\r\n\twhile count <= k:\r\n\t\tsecond = second.next\r\n\t\tcount += 1\r\n\tif second is None:\r\n\t\thead.value = head.next.value\r\n\t\thead.next = head.next.next\r\n\t\treturn\r\n\twhile second.next is not None:\r\n\t\tfirst = first.next\r\n\t\tsecond = second.next\r\n\tfirst.next = first.next.next\r\n\r\n\r\nval = [1, 2, 3, 4, 5]\r\nk = 3\r\nll = LinkedList()\r\nfor i in val:\r\n\tll.create(i)\r\n\r\nprint(\"Linked list before modification:\");\r\nll.display()\r\n\r\nremoveNthFromEnd(ll.head, k)\r\n\r\nprint(\"&#92;nLinked list after modification:\");\r\nll.display()\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_3860 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_3860 a\"),jQuery(\"#tab-content_3860\"));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<h3>Output<\/h3>\n<p>1 2 3 4 5<br \/>\n1 2 4 5<\/p>\n<p>[forminator_quiz id=&#8221;3861&#8243;]<\/p>\n<p><strong>Space complexity:<\/strong> O(1), as we are not using any extra space here.<\/p>\n<p>Here N is the total number of nodes in the given linked list.<\/p>\n<p>Through this article, we learned how to remove the nth node from the end of a linked list. Problems like these are good for strengthening your concepts in LinkedList. I would highly recommend you to practice more such problems from <a href=\"https:\/\/mycode.prepbytes.com\/interview-coding\/practice\/linked-list\">Linked List<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem Statement Given a singly linked list along with a positive integer N. Write a function to delete the Nth node from the end of the given linked list. Problem Statement Understanding Let&#8217;s understand the given problem with the help of some examples: If our initial linked list: It means that here we had to [&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-3859","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>Remove Nth Node From End Of The Linked List in C++<\/title>\n<meta name=\"description\" content=\"Learn to remove the nth node from the end of a linked list. This article explains how to remove the nth node from the end of a linked list\" \/>\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\/remove-nth-node-from-end-of-the-linked-list\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Remove Nth Node From End Of The Linked List in C++\" \/>\n<meta property=\"og:description\" content=\"Learn to remove the nth node from the end of a linked list. This article explains how to remove the nth node from the end of a linked list\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/\" \/>\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-16T12:50:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-08T12:37:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644925925236-105.Remove%20Nth%20Node%20from_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=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Remove Nth Node From End Of The Linked List\",\"datePublished\":\"2021-08-16T12:50:24+00:00\",\"dateModified\":\"2022-03-08T12:37:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/\"},\"wordCount\":750,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644925925236-105.Remove%20Nth%20Node%20from_Artboard%206.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/\",\"name\":\"Remove Nth Node From End Of The Linked List in C++\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644925925236-105.Remove%20Nth%20Node%20from_Artboard%206.png\",\"datePublished\":\"2021-08-16T12:50:24+00:00\",\"dateModified\":\"2022-03-08T12:37:15+00:00\",\"description\":\"Learn to remove the nth node from the end of a linked list. This article explains how to remove the nth node from the end of a linked list\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644925925236-105.Remove%20Nth%20Node%20from_Artboard%206.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644925925236-105.Remove%20Nth%20Node%20from_Artboard%206.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/#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\":\"Remove Nth Node From End Of The Linked List\"}]},{\"@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":"Remove Nth Node From End Of The Linked List in C++","description":"Learn to remove the nth node from the end of a linked list. This article explains how to remove the nth node from the end of a linked list","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\/remove-nth-node-from-end-of-the-linked-list\/","og_locale":"en_US","og_type":"article","og_title":"Remove Nth Node From End Of The Linked List in C++","og_description":"Learn to remove the nth node from the end of a linked list. This article explains how to remove the nth node from the end of a linked list","og_url":"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-08-16T12:50:24+00:00","article_modified_time":"2022-03-08T12:37:15+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644925925236-105.Remove%20Nth%20Node%20from_Artboard%206.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\/remove-nth-node-from-end-of-the-linked-list\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Remove Nth Node From End Of The Linked List","datePublished":"2021-08-16T12:50:24+00:00","dateModified":"2022-03-08T12:37:15+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/"},"wordCount":750,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644925925236-105.Remove%20Nth%20Node%20from_Artboard%206.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/","url":"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/","name":"Remove Nth Node From End Of The Linked List in C++","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644925925236-105.Remove%20Nth%20Node%20from_Artboard%206.png","datePublished":"2021-08-16T12:50:24+00:00","dateModified":"2022-03-08T12:37:15+00:00","description":"Learn to remove the nth node from the end of a linked list. This article explains how to remove the nth node from the end of a linked list","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644925925236-105.Remove%20Nth%20Node%20from_Artboard%206.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644925925236-105.Remove%20Nth%20Node%20from_Artboard%206.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/remove-nth-node-from-end-of-the-linked-list\/#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":"Remove Nth Node From End Of The Linked List"}]},{"@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\/3859","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=3859"}],"version-history":[{"count":6,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/3859\/revisions"}],"predecessor-version":[{"id":7832,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/3859\/revisions\/7832"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=3859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=3859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=3859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}