{"id":5391,"date":"2021-10-07T07:36:56","date_gmt":"2021-10-07T07:36:56","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=5391"},"modified":"2023-11-28T05:09:09","modified_gmt":"2023-11-28T05:09:09","slug":"flatten-a-multi-level-linked-list-depth-wise","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/","title":{"rendered":"Flatten a multi-level linked list (Depth wise)"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011700027-Article_189.png\" alt=\"\" \/><\/p>\n<p>Flattening a multi-level linked list depth-wise involves transforming a nested structure into a flat, one-dimensional linked list. In this context, each node in the list may have a horizontal link to the next node at the same level and a vertical link to a sublist representing a lower level.<\/p>\n<h2>How to flattening a linked list?<\/h2>\n<p>The linked list that we have studied typically has only one pointer, i.e., a <strong>next<\/strong> pointer, which points to the <strong>next<\/strong> node in the linked list. <\/p>\n<p>But, here in this problem, we have a linked list with 2 pointers named <strong>next<\/strong> and <strong>down<\/strong>. <\/p>\n<ul>\n<li>The <strong>next<\/strong> pointer points normally to the <strong>next<\/strong> node.<\/li>\n<li>But the <strong>down<\/strong> pointer points to a node that we assume is present in a <strong>node\u2019s downward direction<\/strong>. <\/li>\n<\/ul>\n<p>Our task is to flatten a linked list containing <strong>next<\/strong> and <strong>down<\/strong> pointers, and also we must make sure that we always process the <strong>down<\/strong> pointer before <strong>next<\/strong> at every node.<\/p>\n<p>According to the problem statement, we have a linked list with 2 pointers named <strong>next<\/strong> and <strong>down<\/strong>, and we need to convert it to the normal linked list that we have studied earlier, i.e., we need to move nodes that are being pointed by the down pointer to next making all down pointers NULL, but also we need to keep in mind that we process down pointer before processing next pointer.<\/p>\n<p>An alternate way to understand flattening a linked list, even more, is to imagine it as a binary tree (as shown in the image below). <\/p>\n<ul>\n<li>And now, all we need to do is to visit each node such that when we are at a <strong>current node<\/strong> then we need to first explore the nodes pointed by <strong>down pointer<\/strong> and when the list with current node&#8217;s down pointer is flattened completely, then we have to move towards node pointed by <strong>next pointer<\/strong> and perform the same task there also.<\/li>\n<\/ul>\n<p>If say our given linked list is:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/p_4.png\" alt=\"\" \/><\/p>\n<ul>\n<li>In this case, our flattened list will be :<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/output.png\" alt=\"\" \/><\/p>\n<p>Now, we just need to perform a preorder traversal of the given linked list recursively, where down nodes will be flattened before the next nodes.<\/p>\n<h2>Approach for flattening a linked list<\/h2>\n<p>I hope that you got a basic idea of what we need to do to solve the flattening a linked list. <\/p>\n<ul>\n<li>The approach will be recursive; we have to consider the given list as a <strong>binary tree<\/strong> and traverse it in a <strong>preorder fashion<\/strong>. <\/li>\n<li>We have to first flatten the <strong>down nodes<\/strong> recursively and then the <strong>next nodes<\/strong>. <\/li>\n<li>Since we need to flatten the list:\n<ul>\n<li>So, we need to visit nodes present in the downward direction first.<\/li>\n<li>We will keep a global pointer <strong>previous<\/strong> that would store the address of the <strong>current node<\/strong> to keep track of the last visited node.<\/li>\n<li>And then, in each recursive call, we would be storing the <strong>next pointer<\/strong> and then call the recursive function for the <strong>down pointer<\/strong> first, and then will do the same for the <strong>next pointer<\/strong> afterwards.<\/li>\n<\/ul>\n<\/li>\n<li>After performing the above steps, our list will get flattened.<\/li>\n<\/ul>\n<h2>Algorithm to flatten a multilevel linked list<\/h2>\n<ul>\n<li>\n<p><strong>Base case:<\/strong> If the <strong>node<\/strong> is NULL, we do not need to do anything and we just return from recursion.<\/p>\n<\/li>\n<li>\n<p>Otherwise, store the address of the <strong>current node<\/strong> in a global variable <strong>previous<\/strong> to keep track of the <strong>last visited node<\/strong>.<\/p>\n<\/li>\n<li>\n<p>Store the <strong>current node\u2019s next<\/strong> node in a variable <strong>next_node<\/strong> because at first, we will be processing <strong>down nodes<\/strong>, and not storing <strong>current node\u2019s next<\/strong> will lead to loss of the <strong>next node<\/strong> and all its connected nodes.<\/p>\n<\/li>\n<li>\n<p>Then, we need to check whether the <strong>down node<\/strong> of the current node exists or not. <\/p>\n<ul>\n<li>If it exists, we recursively call our function for the down node and flatten down nodes first and connect with <strong>current-&gt; next<\/strong>.<\/li>\n<li><strong>current-&gt;next = flatten_linked_list(current-&gt;down)<\/strong>.<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Then we check if the next node <strong>next_node<\/strong> (saved in step 3) exists or not. <\/p>\n<ul>\n<li>If it exists, we again call the recursive function to flatten the linked list and connect it with <strong>previous-&gt; next<\/strong>.<\/li>\n<li><strong>previous-&gt;next = flatten_linked_list(next_node)<\/strong><\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Finally, we return <strong>current<\/strong>.<\/p>\n<\/li>\n<\/ul>\n<h3>Dry Run to flatten a multilevel linked list<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/p_1.png\"><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/p_2.png\"><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/p_3.png\"><\/p>\n<p>## Code Implementation of flattening a linked list<\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_5389 {\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_5389 .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_5389 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_5389 .wpsm_nav-tabs > li.active > a, #tab_container_5389 .wpsm_nav-tabs > li.active > a:hover, #tab_container_5389 .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_5389 .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_5389 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_5389 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_5389 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_5389 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_5389 .wpsm_nav-tabs > li > a:hover , #tab_container_5389 .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_5389 .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_5389 .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_5389 .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_5389 .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_5389 .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_5389 .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_5389 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5389 .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_5389 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5389 .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_5389 .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_5389\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_5389\">\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_5389_1\" aria-controls=\"tabs_desc_5389_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_5389_2\" aria-controls=\"tabs_desc_5389_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_5389_3\" aria-controls=\"tabs_desc_5389_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\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_5389\">\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_5389_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\nstruct Node\r\n{\r\n    int data;\r\n    struct Node *next;\r\n    struct Node *down;\r\n};\r\n \r\n\/\/ Flattens a multi-level linked list depth wise\r\n\r\nstruct Node* flattenList(struct Node* node)\r\n{\r\n    \/\/ Base case\r\n    if (node == NULL)\r\n        return NULL;\r\n \r\n    \/\/ To keep track of last visited node\r\n    \/\/ (NOTE: This is static)\r\n    static struct Node* last;\r\n    last = node;\r\n \r\n    \/\/ Store next pointer\r\n    struct Node *next = node-&gt;next;\r\n \r\n    \/\/ If down list exists, process it first\r\n    \/\/ Add down list as next of current node\r\n    if (node-&gt;down)\r\n       node-&gt;next = flattenList(node-&gt;down);\r\n \r\n    \/\/ If next exists, add it after the next\r\n    \/\/ of last added node\r\n    if (next)\r\n       last-&gt;next = flattenList(next);\r\n \r\n    return node;\r\n}\r\n \r\n\/\/ Utility method to print a linked list\r\nvoid printFlattenNodes(struct Node* head)\r\n{\r\n    while (head)\r\n    {\r\n    printf(&quot;%d &quot;, head-&gt;data);\r\n    head = head-&gt;next;\r\n    }\r\n    \r\n}\r\n \r\n\/\/ Utility function to create a new node\r\nstruct Node* newNode(int new_data)\r\n{\r\n    struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));\r\n    new_node-&gt;data = new_data;\r\n    new_node-&gt;next = new_node-&gt;down = NULL;\r\n    return new_node;\r\n}\r\n \r\n\/\/ Driver code\r\nint main()\r\n{\r\n    \/\/ Creating above example list\r\n    struct Node* head = newNode(1);\r\n    head-&gt;next = newNode(2);\r\n    head-&gt;next-&gt;next = newNode(3);\r\n    head-&gt;next-&gt;next-&gt;next = newNode(4);\r\n    head-&gt;next-&gt;down = newNode(7);\r\n    head-&gt;next-&gt;down-&gt;down = newNode(9);\r\n    head-&gt;next-&gt;down-&gt;down-&gt;down = newNode(14);\r\n    head-&gt;next-&gt;down-&gt;down-&gt;down-&gt;down\r\n                                     = newNode(15);\r\n    head-&gt;next-&gt;down-&gt;down-&gt;down-&gt;down-&gt;next\r\n                                     = newNode(23);\r\n    head-&gt;next-&gt;down-&gt;down-&gt;down-&gt;down-&gt;next-&gt;down\r\n                                      = newNode(24);\r\n    head-&gt;next-&gt;down-&gt;next = newNode(8);\r\n    head-&gt;next-&gt;down-&gt;next-&gt;down = newNode(16);\r\n    head-&gt;next-&gt;down-&gt;next-&gt;down-&gt;down = newNode(17);\r\n    head-&gt;next-&gt;down-&gt;next-&gt;down-&gt;down-&gt;next\r\n                                      = newNode(18);\r\n    head-&gt;next-&gt;down-&gt;next-&gt;down-&gt;down-&gt;next-&gt;next\r\n                                      = newNode(19);\r\n    head-&gt;next-&gt;down-&gt;next-&gt;down-&gt;down-&gt;next-&gt;next-&gt;next\r\n                                      = newNode(20);\r\n    head-&gt;next-&gt;down-&gt;next-&gt;down-&gt;down-&gt;next-&gt;next-&gt;next-&gt;down\r\n                                      = newNode(21);\r\n    head-&gt;next-&gt;down-&gt;next-&gt;next = newNode(10);\r\n    head-&gt;next-&gt;down-&gt;next-&gt;next-&gt;down = newNode(11);\r\n \r\n    head-&gt;next-&gt;down-&gt;next-&gt;next-&gt;next = newNode(12);\r\n \r\n    \/\/ Flatten list and print modified list\r\n    head = flattenList(head);\r\n    printFlattenNodes(head);\r\n \r\n    return 0;\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_5389_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 linked list node *\/\r\nstruct Node\r\n{\r\n    int data;\r\n    struct Node *next;\r\n    struct Node *down;\r\n};\r\n\r\n\/* Using this function we will be creating a new list node *\/\r\nNode* createNode(int new_data)\r\n{\r\n    Node* new_node = new Node;\r\n    new_node-&gt;data = new_data;\r\n    new_node-&gt;next = new_node-&gt;down = NULL;\r\n    return new_node;\r\n}\r\n\r\n\/* The global node as discussed in step 2 *\/\r\nNode *previous = NULL;\r\n\r\n\/* Using this function we will be flattening the multilevel linked list *\/\r\nNode* flatten_linked_list(Node* current)\r\n{\r\n\t\/\/ Base case\r\n\tif (current == NULL)\r\n\t\treturn NULL;\r\n\r\n\tprevious = current;\/\/ storing current node address as\r\n\t\/\/discussed in step 2\r\n\r\n\tNode *next_node = current-&gt;next;\/\/ storing current\r\n\t\/\/ node&rsquo;s next as discussed in step 3 \r\n\r\n\t\/\/ if down pointer of current node is not null then, we\r\n\t\/\/ process it first\r\n\tif (current-&gt;down != NULL)\r\n\tcurrent-&gt;next = flatten_linked_list(current-&gt;down);\r\n\t\/\/ If the next node that we discussed in step 3 is not null\r\n\t\/\/ then we process it\r\n\tif (next_node != NULL)\r\n\tprevious-&gt;next = flatten_linked_list(next_node);\r\n\r\n\treturn current;\r\n}\r\n\r\n\/* Using this function we will be printing the content of the linked list *\/\r\nvoid print_linked_list(Node* head)\r\n{\r\n\twhile (head != NULL)\r\n\t{\r\n\t\tcout&lt;&lt;(head-&gt;data)&lt;&lt;&quot; &quot;;\r\n\t\thead = head-&gt;next;\r\n\t}\r\n\tcout&lt;&lt;endl;\r\n}\r\n\r\n\/* Main driver function *\/\r\nint main()\r\n{\r\n\tNode* head = createNode(1);\r\n\thead-&gt;next = createNode(2);\r\n\thead-&gt;next-&gt;next = createNode(5);\r\n\thead-&gt;next-&gt;down = createNode(6);\r\n\thead-&gt;next-&gt;down-&gt;down = createNode(35);\r\n\thead-&gt;next-&gt;down-&gt;down-&gt;down = createNode(28);\r\n\thead-&gt;next-&gt;down-&gt;down-&gt;next = createNode(4);\r\n\thead-&gt;next-&gt;down-&gt;down-&gt;next-&gt;down = createNode(0);\r\n\thead-&gt;next-&gt;down-&gt;down-&gt;next-&gt;next = createNode(3);\r\n\t\r\n\thead = flatten_linked_list(head);\r\n\tcout&lt;&lt;&quot;The linked list after flattening: &quot;;\r\n\tprint_linked_list(head);\r\n\treturn 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_5389_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,down;\r\n    Node(int data)\r\n    {\r\n        this.data=data;\r\n        next=null;\r\n        down=null;\r\n    }\r\n}\r\nclass Flatten \r\n{\r\n\r\n    static Node last;\r\n\r\n    \/\/ Flattens a multi-level linked list depth wise\r\n    public static Node flattenList(Node node)\r\n    {\r\n        if(node==null)\r\n            return null;\r\n\r\n        \/\/ To keep track of last visited node\r\n        \/\/ (NOTE: This is static)\r\n        last = node;\r\n\r\n        \/\/ Store next pointer\r\n        Node next = node.next;\r\n\r\n        \/\/ If down list exists, process it first\r\n        \/\/ Add down list as next of current node\r\n        if(node.down!=null)\r\n            node.next = flattenList(node.down);\r\n\r\n        \/\/ If next exists, add it after the next\r\n        \/\/ of last added node\r\n        if(next!=null)\r\n            last.next = flattenList(next);\r\n\r\n        return node;\r\n    }\r\n    public static void printFlattenNodes(Node head)\r\n    {\r\n        Node curr=head;\r\n        while(curr!=null)\r\n        {\r\n            System.out.print(curr.data+&quot; &quot;);\r\n            curr = curr.next;\r\n        }\r\n        \r\n    }\r\n    public static Node push(int newData)\r\n    {\r\n        Node newNode = new Node(newData);\r\n        newNode.next =null;\r\n        newNode.down = null;\r\n        return newNode;\r\n    }\r\n    \r\n    public static void main(String args[]) {\r\n        Node head=new Node(1);\r\n        head.next = new Node(2);\r\n        head.next.next = new Node(5);\r\n        head.next.down = new Node(6);\r\n        head.next.down.down = new Node(35);\r\n        head.next.down.down.down = new Node(28);\r\n        head.next.down.down.next= new Node(4);\r\n        head.next.down.down.next.down= new Node(0);\r\n        head.next.down.down.next.next = new Node(3);\r\n        \r\n        System.out.println(&quot;The linked list after flattening&quot;);\r\n        head = flattenList(head);\r\n        printFlattenNodes(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\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_5389 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_5389 a\"),jQuery(\"#tab-content_5389\"));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<p>    Output<br \/>\n    The linked list after flattening: 1 2 6 35 28 4 0 3 5<\/p>\n<p><strong>Time Complexity<\/strong>: O(n), where n is the number of nodes in the list.<\/p>\n<p>**Conclusion**<br \/>\nFlattening a multi-level linked list depth-wise involves reorganizing a complex linked list structure, where nodes have both horizontal and vertical connections, into a single-level linked list that maintains the original order of elements<\/p>\n<p>## FAQs related to Flatten a multi-level linked list (Depth wise)<br \/>\nHere are some FAQs related to Flatten a multi-level linked list (Depth wise):<\/p>\n<p>**1. Why would I need to flatten a multi-level linked list?**<br \/>\nFlattening is beneficial when you want to simplify the structure for operations like searching, sorting, or printing elements. It transforms a hierarchical organization into a linear one.<\/p>\n<p>**2. What is the significance of horizontal and vertical traversal in flattening?**<br \/>\nHorizontal traversal is used to connect nodes at the same level, while vertical traversal is necessary to explore and connect lower-level sublists. Both are essential for the flattening process.<\/p>\n<p>**3. How does flattening impact the time complexity of operations?**<br \/>\nFlattening can improve the efficiency of certain operations by converting the structure to a linear form, making it easier to perform operations with a lower time complexity.<\/p>\n<p>**4. Are there any challenges in implementing the flattening algorithm?**<br \/>\nYes, implementing the algorithm requires careful management of pointers and connections to ensure the correct flattening of the linked list. Proper handling of edge cases, such as empty sublists, is crucial.<\/p>\n<p>**5. Can flattening be done in-place, or does it require extra space?**<br \/>\nFlattening can often be done in-place, without requiring additional space, by appropriately adjusting pointers and connections during the traversal.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Flattening a multi-level linked list depth-wise involves transforming a nested structure into a flat, one-dimensional linked list. In this context, each node in the list may have a horizontal link to the next node at the same level and a vertical link to a sublist representing a lower level. How to flattening a linked list? [&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-5391","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>Flatten a multi-level linked list (Depth wise)<\/title>\n<meta name=\"description\" content=\"In this blog, we have tried to explain how you can Flatten a multi-level linked list in depthwise order.\" \/>\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\/flatten-a-multi-level-linked-list-depth-wise\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Flatten a multi-level linked list (Depth wise)\" \/>\n<meta property=\"og:description\" content=\"In this blog, we have tried to explain how you can Flatten a multi-level linked list in depthwise order.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/\" \/>\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-07T07:36:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-28T05:09:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011700027-Article_189.png\" \/>\n<meta name=\"author\" content=\"PrepBytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"PrepBytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/\"},\"author\":{\"name\":\"PrepBytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e\"},\"headline\":\"Flatten a multi-level linked list (Depth wise)\",\"datePublished\":\"2021-10-07T07:36:56+00:00\",\"dateModified\":\"2023-11-28T05:09:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/\"},\"wordCount\":979,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011700027-Article_189.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/\",\"name\":\"Flatten a multi-level linked list (Depth wise)\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011700027-Article_189.png\",\"datePublished\":\"2021-10-07T07:36:56+00:00\",\"dateModified\":\"2023-11-28T05:09:09+00:00\",\"description\":\"In this blog, we have tried to explain how you can Flatten a multi-level linked list in depthwise order.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011700027-Article_189.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011700027-Article_189.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/#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\":\"Flatten a multi-level linked list (Depth wise)\"}]},{\"@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":"Flatten a multi-level linked list (Depth wise)","description":"In this blog, we have tried to explain how you can Flatten a multi-level linked list in depthwise order.","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\/flatten-a-multi-level-linked-list-depth-wise\/","og_locale":"en_US","og_type":"article","og_title":"Flatten a multi-level linked list (Depth wise)","og_description":"In this blog, we have tried to explain how you can Flatten a multi-level linked list in depthwise order.","og_url":"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-10-07T07:36:56+00:00","article_modified_time":"2023-11-28T05:09:09+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011700027-Article_189.png","type":"","width":"","height":""}],"author":"PrepBytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"PrepBytes","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/"},"author":{"name":"PrepBytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e"},"headline":"Flatten a multi-level linked list (Depth wise)","datePublished":"2021-10-07T07:36:56+00:00","dateModified":"2023-11-28T05:09:09+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/"},"wordCount":979,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011700027-Article_189.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/","url":"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/","name":"Flatten a multi-level linked list (Depth wise)","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011700027-Article_189.png","datePublished":"2021-10-07T07:36:56+00:00","dateModified":"2023-11-28T05:09:09+00:00","description":"In this blog, we have tried to explain how you can Flatten a multi-level linked list in depthwise order.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011700027-Article_189.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011700027-Article_189.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/flatten-a-multi-level-linked-list-depth-wise\/#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":"Flatten a multi-level linked list (Depth wise)"}]},{"@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\/5391","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=5391"}],"version-history":[{"count":9,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5391\/revisions"}],"predecessor-version":[{"id":18401,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5391\/revisions\/18401"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=5391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=5391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=5391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}