{"id":5114,"date":"2021-10-04T11:01:39","date_gmt":"2021-10-04T11:01:39","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=5114"},"modified":"2022-03-09T07:56:59","modified_gmt":"2022-03-09T07:56:59","slug":"reverse-a-doubly-linked-list-in-groups-of-given-size","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/","title":{"rendered":"Reverse a doubly-linked list in groups of given size"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645008788011-Article_176.png\" alt=\"\" \/><\/p>\n<h3>Introduction<\/h3>\n<p>One of the most crucial data structures to learn while preparing for interviews is the linked list. In a coding interview, having a thorough understanding of Linked Lists might be a major benefit.<\/p>\n<\/p>\n<h3>Problem Statement<\/h3>\n<p>In this problem, we are given a Doubly Linked List and an integer <strong>X<\/strong>. We are asked to reverse the list in groups of size <strong>X<\/strong>.<\/p>\n<h3>Problem Statement Understanding<\/h3>\n<p>Let\u2019s try to understand the problem statement with the help of examples.<\/p>\n<p>If the given doubly linked list is: 5  1  6  2  7  10 and <strong>X = 3<\/strong>.<\/p>\n<ul>\n<li>According to the problem statement, we have been provided a doubly-linked list, and we need to reverse the list in groups of given size i.e. every group of nodes with the size <strong>X<\/strong> needs to be reversed.<\/li>\n<li>As we can see in the above given doubly linked list there are two groups 5  1  6 (from index 0 to 2) and 2  7  10 (from index 3 to 5) of size 3 which need to be reversed.<\/li>\n<li>So after reversing the group of nodes of size 3, our output resultant doubly linked list will be 6  1  5  10  7  2.<\/li>\n<\/ul>\n<p>Let&#8217;s see another example.<\/p>\n<p>If the given doubly linked list is: 5  1  6  2  7 and <strong>X = 3<\/strong>.<\/p>\n<ul>\n<li>As we can see in the above given doubly linked list 5  1  6 is a group of nodes of size 3 and 2  7 is a group of size 2. So, we need to reverse these two group of nodes.<\/li>\n<li>After reversing the above mentioned group of nodes, our resultant doubly linked list will be 6  1  5  7  2<\/li>\n<\/ul>\n<p><strong>Note:<\/strong> Suppose we were asked to reverse every group of nodes of size <strong>X<\/strong> in a doubly linked list. If in case there remains a group of nodes at the end of the linked list which has size smaller than X, then irrespective of its size we will reverse it in similar way as we were reversing nodes of group of size X.<\/p>\n<p>Now I think from the above examples, the problem is clear. So let\u2019s see how we can approach it.<\/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<p>Our approach will be recursive:<\/p>\n<ul>\n<li>Here the main idea will be to use recursion to reverse the Doubly Linked List in group of given size, and after reversing a group, we need to call the function again for the next group of nodes if the next node is not null. <\/li>\n<li>The function will be called recursively until there are no elements left to be reversed.<\/li>\n<li>After the recursion is over, we will have our doubly linked list reversed in group of given size.<\/li>\n<\/ul>\n<h3>Algorithm<\/h3>\n<p>1) Our recursive function <strong>reverseListInGroupOfX()<\/strong> will receive the first node of every group of size <strong>X<\/strong> of the doubly linked list.<br \/>\n2) For every group of nodes in the recursive function <strong>reverseListInGroupOfX()<\/strong>:<\/p>\n<ul>\n<li>First, we will reverse the nodes in the current group.<\/li>\n<li>After the nodes of the current group have been reversed, we will check whether the next group of nodes exists or not:\n<ul>\n<li>If the next group of nodes exists, we will perform the same steps for the next group of nodes that we are performing for the current group.<\/li>\n<li>Also, for the current group of nodes, we need to link the next and the prev links of a group properly with the next group of nodes and previous group of nodes.<\/li>\n<\/ul>\n<\/li>\n<li>Finally, we will return the new head of the group.<br \/>\n3) Following all these above steps until all the group of nodes have been reversed, we will get our resultant doubly linked list.<\/li>\n<\/ul>\n<h3>Dry Run<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_1-38.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_2-37.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_3-23.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_5115 {\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_5115 .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_5115 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_5115 .wpsm_nav-tabs > li.active > a, #tab_container_5115 .wpsm_nav-tabs > li.active > a:hover, #tab_container_5115 .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_5115 .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_5115 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_5115 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_5115 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_5115 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_5115 .wpsm_nav-tabs > li > a:hover , #tab_container_5115 .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_5115 .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_5115 .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_5115 .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_5115 .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_5115 .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_5115 .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_5115 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5115 .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_5115 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5115 .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_5115 .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_5115\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_5115\">\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_5115_1\" aria-controls=\"tabs_desc_5115_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_5115_2\" aria-controls=\"tabs_desc_5115_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_5115_3\" aria-controls=\"tabs_desc_5115_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_5115_4\" aria-controls=\"tabs_desc_5115_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_5115\">\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_5115_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&lt;stdio.h&gt;\r\n#include&lt;stdlib.h&gt;\r\n\r\nstruct Node {\r\n    int data;\r\n    struct Node *next, *prev;\r\n};\r\n  \r\n\/\/ function to get a new node\r\nstruct Node* getNode(int data)\r\n{\r\n    \/\/ allocate space\r\n    struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));\r\n  \r\n    \/\/ put in the data\r\n    new_node-&gt;data = data;\r\n    new_node-&gt;next = new_node-&gt;prev = NULL;\r\n    return new_node;\r\n}\r\n  \r\n\/\/ function to insert a node at the beginning\r\n\/\/ of the Doubly Linked List\r\nvoid push(struct Node** head_ref,struct Node* new_node)\r\n{\r\n    \/\/ since we are adding at the beginning,\r\n    \/\/ prev is always NULL\r\n    new_node-&gt;prev = NULL;\r\n  \r\n    \/\/ link the old list off the new node\r\n    new_node-&gt;next = (*head_ref);\r\n  \r\n    \/\/ change prev of head node to new node\r\n    if ((*head_ref) != NULL)\r\n        (*head_ref)-&gt;prev = new_node;\r\n  \r\n    \/\/ move the head to point to the new node\r\n    (*head_ref) = new_node;\r\n}\r\n \r\n\/\/ function to reverse a doubly linked list\r\n\/\/ in groups of given size\r\nstruct Node* revListInGroupOfGivenSize(struct Node* head, int k)\r\n{\r\n    struct Node *current = head;\r\n    struct Node* next = NULL;\r\n    struct Node* newHead = NULL;\r\n    int count = 0;\r\n     \r\n    \/\/ reversing the current group of k\r\n    \/\/ or less than k nodes by adding\r\n    \/\/ them at the beginning of list\r\n    \/\/ 'newHead'\r\n    while (current != NULL &amp;&amp; count &lt; k)\r\n    {\r\n        next = current-&gt;next;\r\n        push(&amp;newHead, current);\r\n        current = next;\r\n        count++;\r\n    }\r\n     \r\n    \/\/ if next group exists then making the desired\r\n    \/\/ adjustments in the link\r\n    if (next != NULL)\r\n    {\r\n        head-&gt;next = revListInGroupOfGivenSize(next, k);\r\n        head-&gt;next-&gt;prev = head;\r\n    }\r\n     \r\n    \/\/ pointer to the new head of the\r\n    \/\/ reversed group\r\n    \/\/ pointer to the new head should point to NULL, otherwise you won't be able to traverse list in reverse order using 'prev'\r\n    newHead-&gt;prev = NULL;\r\n    return newHead;\r\n}\r\n \r\n\/\/ Function to print nodes in a\r\n\/\/ given doubly linked list\r\nvoid printList(struct Node* head)\r\n{\r\n    while (head != NULL) {\r\n        printf(&quot;%d &quot;,head-&gt;data);\r\n        head = head-&gt;next;\r\n    }\r\n}\r\n  \r\n\/\/ Driver program to test above\r\nint main()\r\n{\r\n    \/\/ Start with the empty list\r\n    struct Node* head = NULL;\r\n  \r\n    \/\/ Create doubly linked: 10&lt;-&gt;8&lt;-&gt;4&lt;-&gt;2\r\n    push(&amp;head, getNode(2));\r\n    push(&amp;head, getNode(4));\r\n    push(&amp;head, getNode(8));\r\n    push(&amp;head, getNode(10));\r\n     \r\n    int k = 2;\r\n  \r\n    printf(&quot;Original list: &quot;);\r\n    printList(head);\r\n  \r\n    \/\/ Reverse doubly linked list in groups of\r\n    \/\/ size 'k'\r\n    head = revListInGroupOfGivenSize(head, k);\r\n  \r\n    printf(&quot;&#92;nModified list: &quot;);\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_5115_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 &lt;bits\/stdc++.h&gt;\r\nusing namespace std;\r\n\r\n\/* Structure of a doubly linked list node *\/\r\nstruct Node {\r\n    int data;\r\n    Node *next, *prev;\r\n};\r\n\r\n\/* Creating and returning a new doubly linked list node *\/\r\nNode* getNewNode(int data)\r\n{\r\n    Node* new_node = (Node*)malloc(sizeof(Node));\r\n\r\n    new_node-&gt;data = data;\r\n    new_node-&gt;next = new_node-&gt;prev = NULL;\r\n    return new_node;\r\n}\r\n\r\n\/* Inserting a new node at head of doubly linked list *\/\r\nvoid push(Node** newHead, Node* new_node)\r\n{\r\n\r\n    new_node-&gt;prev = NULL;\r\n\r\n    new_node-&gt;next = (*newHead);\r\n\r\n    if ((*newHead) != NULL)\r\n        (*newHead)-&gt;prev = new_node;\r\n\r\n    (*newHead) = new_node;\r\n}\r\n\r\n\/* Using this function we will be reversing doubly linked list in group of given size *\/\r\nNode* reverseListInGroupOfX(Node* head, int X)\r\n{\r\n    Node *current = head;\r\n    Node* next = NULL;\r\n    Node* newHead = NULL;\r\n    int count = 0;\r\n\r\n    while (current != NULL &amp;&amp; count &lt; X)\r\n    {\r\n        next = current-&gt;next;\r\n        push(&amp;newHead, current);\r\n        current = next;\r\n        count++;\r\n    }\r\n\r\n    if (next != NULL)\r\n    {\r\n        head-&gt;next = reverseListInGroupOfX(next, X);\r\n        head-&gt;next-&gt;prev = head;\r\n    }\r\n    return newHead;\r\n}\r\n\r\n\/* Using this function we will be printing the linked list content *\/\r\nvoid printLinkedList(Node* head)\r\n{\r\n    while (head != NULL) {\r\n        cout &lt;&lt; head-&gt;data &lt;&lt; &quot; &quot;;\r\n        head = head-&gt;next;\r\n    }\r\n    cout&lt;&lt;endl;\r\n}\r\n\r\nint main()\r\n{\r\n    Node* head = NULL;\r\n    push(&amp;head, getNewNode(10));\r\n    push(&amp;head, getNewNode(7));\r\n    push(&amp;head, getNewNode(2));\r\n    push(&amp;head, getNewNode(6));\r\n    push(&amp;head, getNewNode(1));\r\n    push(&amp;head, getNewNode(5));\r\n    \r\n    int X = 3;\r\n    cout&lt;&lt;&quot;Initial doubly linked list&quot;&lt;&lt;endl;\r\n    printLinkedList(head);\r\n    head = reverseListInGroupOfX(head, X);\r\n    cout&lt;&lt;&quot;Doubly linked list after reversing in group of given size&quot;&lt;&lt;endl;\r\n    printLinkedList(head);\r\n\r\n    return 0;\r\n}\r\n\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_5115_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{\r\n    int data;\r\n    Node next, prev;\r\n}\r\n \r\nclass ReverseGroups\r\n{\r\n \r\n    static Node getNode(int data)\r\n    {\r\n        \r\n        Node new_node = new Node();\r\n        new_node.data = data;\r\n        new_node.next = new_node.prev = null;\r\n \r\n        return new_node;\r\n    }\r\n    static Node push(Node head, Node new_node)\r\n    {\r\n        new_node.prev = null;\r\n        new_node.next = head;\r\n        if (head != null)\r\n            head.prev = new_node;\r\n\r\n        head = new_node;\r\n        return head;\r\n    }\r\n    \/\/ reversing doubly linked list in group of given size.\r\n    static Node revListInGroupOfGivenSize(Node head, int k)\r\n    {\r\n        Node current = head;\r\n        Node next = null;\r\n        Node newHead = null;\r\n        int count = 0;\r\n\r\n        while (current != null &amp;&amp; count &lt; k)\r\n        {\r\n            next = current.next;\r\n            newHead = push(newHead, current);\r\n            current = next;\r\n            count++;\r\n        }\r\n        if (next != null)\r\n        {\r\n            head.next = revListInGroupOfGivenSize(next, k);\r\n            head.next.prev = head;\r\n        }\r\n        return newHead;\r\n    }\r\n    static void printLinkedList(Node head)\r\n    {\r\n        while (head != null)\r\n        {\r\n            System.out.print(head.data + &quot; &quot;);\r\n            head = head.next;\r\n        }\r\n    }\r\n    public static void main(String args[])\r\n    {\r\n        Node head = null;\r\n        head = push(head, getNode(2));\r\n        head = push(head, getNode(4));\r\n        head = push(head, getNode(8));\r\n        head = push(head, getNode(10));\r\n \r\n        int k = 2;\r\n             \r\n        System.out.print(&quot;Original list: &quot;);\r\n        printLinkedList(head);\r\n \r\n        head = revListInGroupOfGivenSize(head, k);\r\n \r\n        System.out.print(&quot;&#92;nModified list in groups: &quot;);\r\n        printLinkedList(head);\r\n    }\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_5115_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\n# Structure of a doubly linked list node\r\nclass Node:\r\n\t\r\n\tdef __init__(self, data):\r\n\t\tself.data = data\r\n\t\tself.next = None\r\n\t\tself.prev = None\r\n\t\t\r\n# Creating and returning a new doubly linked list node\r\ndef getNode(data):\r\n\r\n\tnew_node = Node(0)\r\n\r\n\tnew_node.data = data\r\n\tnew_node.next = new_node.prev = None\r\n\treturn new_node\r\n\r\n# Inserting a new node at head of doubly linked list\r\ndef push(newHead, new_node):\r\n\r\n\tnew_node.prev = None\r\n\tnew_node.next = (newHead)\r\n\r\n\tif ((newHead) != None):\r\n\t\t(newHead).prev = new_node\r\n\r\n\t(newHead) = new_node\r\n\treturn newHead\r\n\r\n# Using this function we will be reversing doubly linked list in group of given size\r\ndef revListInGroupOfGivenSize( head, k):\r\n\r\n\tcurrent = head\r\n\tnext = None\r\n\tnewHead = None\r\n\tcount = 0\r\n\r\n\twhile (current != None and count &lt; k):\r\n\t\r\n\t\tnext = current.next\r\n\t\tnewHead = push(newHead, current)\r\n\t\tcurrent = next\r\n\t\tcount = count + 1\r\n\r\n\tif (next != None):\r\n\t\r\n\t\thead.next = revListInGroupOfGivenSize(next, k)\r\n\t\thead.next.prev = head\r\n\r\n\treturn newHead\r\n\r\n# Using this function we will be printing the linked list content\r\ndef printList(head):\r\n\r\n\twhile (head != None):\r\n\t\tprint( head.data , end=&quot; &quot;)\r\n\t\thead = head.next\r\n\t\r\nhead = None\r\n\r\nhead = push(head, getNode(10))\r\nhead = push(head, getNode(7))\r\nhead = push(head, getNode(2))\r\nhead = push(head, getNode(6))\r\nhead = push(head, getNode(1))\r\nhead = push(head, getNode(5))\r\n\t\r\nk = 3\r\n\r\nprint(&quot;Initial doubly linked list&quot;)\r\nprintList(head)\r\n\r\nhead = revListInGroupOfGivenSize(head, k)\r\n\r\nprint(&quot;&#92;nDoubly linked list after reversing in group of given size&quot;)\r\nprintList(head)\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\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_5115 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_5115 a\"),jQuery(\"#tab-content_5115\"));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>Initial doubly linked list<br \/>\n5 1 6 2 7 10<br \/>\nDoubly linked list after reversing in group of given size<br \/>\n6 1 5 10 7 2 <\/p>\n<p><strong>Time Complexity:<\/strong> O(n), as we need to traverse the list and traversing takes O(n) time.<br \/>\n[forminator_quiz id=&#8221;5116&#8243;]<\/p>\n<p>So, In this blog, we have learned how you can reverse a Doubly Linked List in groups of a given size. 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 One of the most crucial data structures to learn while preparing for interviews is the linked list. In a coding interview, having a thorough understanding of Linked Lists might be a major benefit. Problem Statement In this problem, we are given a Doubly Linked List and an integer X. We are asked to reverse [&hellip;]<\/p>\n","protected":false},"author":3,"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-5114","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>Reverse a doubly-linked list in groups of given size | Linked list articles | PrepBytes Blog<\/title>\n<meta name=\"description\" content=\"Learn the most efficient way to reverse a Doubly Linked List in groups of given size.\" \/>\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\/reverse-a-doubly-linked-list-in-groups-of-given-size\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Reverse a doubly-linked list in groups of given size | Linked list articles | PrepBytes Blog\" \/>\n<meta property=\"og:description\" content=\"Learn the most efficient way to reverse a Doubly Linked List in groups of given size.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/\" \/>\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-04T11:01:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-09T07:56:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645008788011-Article_176.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=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/\"},\"author\":{\"name\":\"PrepBytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e\"},\"headline\":\"Reverse a doubly-linked list in groups of given size\",\"datePublished\":\"2021-10-04T11:01:39+00:00\",\"dateModified\":\"2022-03-09T07:56:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/\"},\"wordCount\":694,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645008788011-Article_176.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/\",\"name\":\"Reverse a doubly-linked list in groups of given size | Linked list articles | PrepBytes Blog\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645008788011-Article_176.png\",\"datePublished\":\"2021-10-04T11:01:39+00:00\",\"dateModified\":\"2022-03-09T07:56:59+00:00\",\"description\":\"Learn the most efficient way to reverse a Doubly Linked List in groups of given size.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645008788011-Article_176.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645008788011-Article_176.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/#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\":\"Reverse a doubly-linked list in groups of given size\"}]},{\"@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\/39fcf072e04987f16796546f2ca83c2e\",\"name\":\"PrepBytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g\",\"caption\":\"PrepBytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/prepbytes\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Reverse a doubly-linked list in groups of given size | Linked list articles | PrepBytes Blog","description":"Learn the most efficient way to reverse a Doubly Linked List in groups of given size.","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\/reverse-a-doubly-linked-list-in-groups-of-given-size\/","og_locale":"en_US","og_type":"article","og_title":"Reverse a doubly-linked list in groups of given size | Linked list articles | PrepBytes Blog","og_description":"Learn the most efficient way to reverse a Doubly Linked List in groups of given size.","og_url":"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-10-04T11:01:39+00:00","article_modified_time":"2022-03-09T07:56:59+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645008788011-Article_176.png","type":"","width":"","height":""}],"author":"PrepBytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"PrepBytes","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/"},"author":{"name":"PrepBytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e"},"headline":"Reverse a doubly-linked list in groups of given size","datePublished":"2021-10-04T11:01:39+00:00","dateModified":"2022-03-09T07:56:59+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/"},"wordCount":694,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645008788011-Article_176.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/","url":"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/","name":"Reverse a doubly-linked list in groups of given size | Linked list articles | PrepBytes Blog","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645008788011-Article_176.png","datePublished":"2021-10-04T11:01:39+00:00","dateModified":"2022-03-09T07:56:59+00:00","description":"Learn the most efficient way to reverse a Doubly Linked List in groups of given size.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645008788011-Article_176.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645008788011-Article_176.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/reverse-a-doubly-linked-list-in-groups-of-given-size\/#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":"Reverse a doubly-linked list in groups of given size"}]},{"@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\/39fcf072e04987f16796546f2ca83c2e","name":"PrepBytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g","caption":"PrepBytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/prepbytes\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5114","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\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=5114"}],"version-history":[{"count":5,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5114\/revisions"}],"predecessor-version":[{"id":7838,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5114\/revisions\/7838"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=5114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=5114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=5114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}