{"id":1806,"date":"2020-06-11T18:01:04","date_gmt":"2020-06-11T18:01:04","guid":{"rendered":"https:\/\/blog.prepbytes.com\/?p=1806"},"modified":"2022-11-28T07:15:45","modified_gmt":"2022-11-28T07:15:45","slug":"merge-k-sorted-linked-lists","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/","title":{"rendered":"MERGE K SORTED LINKED LISTS"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645174449305-Article_399.png\" alt=\"\" \/><\/p>\n<p>In this blog, we will discuss three different approaches to merge k sorted lists. Merging k sorted linked lists is a challenging topic and conquering it will make your data structures more efficient. Let\u2019s discuss how to merge k sorted lists.<\/p>\n<h2>How to Merge K Sorted Linked List?<\/h2>\n<blockquote>\n<p>Yor are given K sorted linked lists. You have to merge K sorted linked lists into one sorted list. The size of the linked list maybe different.<\/p>\n<\/blockquote>\n<p><a href=\"https:\/\/mycode.prepbytes.com\/problems\/linked-list\/MERGEKSORLIST\" title=\"Go to mycode.prepbytes.com\" target=\"_blank\" rel=\"noopener noreferrer\"><u><strong><\/strong><\/u><\/a><\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre><code>Input:\n[\nlist[1]:4\u2212&gt;6\u2212&gt;8\u2212&gt;10\u2212&gt;15\nlist[2]:1\u2212&gt;5\u2212&gt;9\nlist[3]:2\u2212&gt;3\u2212&gt;7\u2212&gt;11\n]\n\nOutput: \n1\u2212&gt;2\u2212&gt;3\u2212&gt;4\u2212&gt;5\u2212&gt;6\u2212&gt;7\u2212&gt;8\u2212&gt;9\u2212&gt;10\u2212&gt;11\u2212&gt;15<\/code><\/pre>\n<h2>EXPLANATION:<\/h2>\n<h3>Approach 1 To Merge K Sorted Lists<code>(Brute force):<\/code><\/h3>\n<blockquote>\n<p>All the given lists are sorted, which means that the head of each list would be the smallest element in its chain. So we could extract the minimum from the k head nodes and append it to the result list.<\/p>\n<p><code>Time complexity To Merge K Sorted Lists In Brute Force approach<\/code>: <code>O(kN)<\/code> where <code>k<\/code> is the number of linked lists. Almost every selection of nodes in the final link costs <code>O(k)<\/code> <code>(k-1 times comparison)<\/code>.<\/p>\n<p><code>Space complexity To Merge K Sorted Lists<\/code>: <code>O(1)<\/code>. <\/p>\n<\/blockquote>\n<h3>Approach 2 To Merge K Sorted Lists:<\/h3>\n<p>The idea is to insert all the node values from all the <code>k<\/code> lists into an array. Sorting the array and creating a new linked list from the sorted array will give the required output.<\/p>\n<p><strong>Pseudo code:<\/strong><\/p>\n<pre><code>     ListNode mergeKLists(ListNode[] lists, int k)\n     {\n    \/\/ x array to store all the values from lists\n    int x[]\n    for(i = 0 to k) \n    {\n        ListNode temp = lists[i]\n        while(temp is not null)\n       {\n            \/\/ append the value of temp to x\n            x.add(temp.val)\n            temp = temp.next\n        }\n    }\n    \/\/ sort all the values of x\n    sort(x)\n    \/\/ Head node to return\n    ListNode head(-1)\n    ListNode temp = head\n    for(i = 0 to x.size()) {\n        ListNode newVal(x[i])\n        temp.next = newVal\n        temp = temp.next\n    }\n    return head.next\n    } <\/code><\/pre>\n<blockquote>\n<p><code>TIME COMPLEXITY To Merge K Sorted Lists<\/code>: O(NlogN).<br \/>\n<code>SPACE COMPLEXITY To Merge K Sorted Lists<\/code>: O(N),<br \/>\nwhere <code>N<\/code> is the total number of nodes<\/p>\n<\/blockquote>\n<h3>Approach 3 To Merge K Sorted Lists<code>(Heaps):<\/code><\/h3>\n<ol>\n<li>Create a priority queue.<\/li>\n<li>Insert the first node from all the lists into the priority queue.<\/li>\n<li>Loop until the priority queue is not empty Extract the minimum node from the queue and add it to our result list.<\/li>\n<li>Add the next node (if present) from the extracted node list.<\/li>\n<li>Return the resultant list.<\/li>\n<\/ol>\n<h2>SOLUTIONS To Merge K Sorted Lists:<\/h2>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_1807 {\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_1807 .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_1807 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_1807 .wpsm_nav-tabs > li.active > a, #tab_container_1807 .wpsm_nav-tabs > li.active > a:hover, #tab_container_1807 .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_1807 .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_1807 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_1807 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_1807 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_1807 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_1807 .wpsm_nav-tabs > li > a:hover , #tab_container_1807 .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_1807 .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_1807 .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_1807 .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_1807 .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_1807 .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_1807 .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_1807 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_1807 .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_1807 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_1807 .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_1807 .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_1807\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_1807\">\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_1807_1\" aria-controls=\"tabs_desc_1807_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_1807_2\" aria-controls=\"tabs_desc_1807_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_1807_3\" aria-controls=\"tabs_desc_1807_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_1807_4\" aria-controls=\"tabs_desc_1807_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_1807\">\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_1807_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    int data;\r\n    struct Node* next;\r\n};\r\n \r\n\/* Function to print nodes in\r\n   a given linked list *\/\r\nvoid printList(struct Node* node)\r\n{\r\n    while (node != NULL) {\r\n        printf(\"%d \", node->data);\r\n        node = node->next;\r\n    }\r\n}\r\n \r\n\/* Takes two lists sorted in increasing order, and merge\r\n   their nodes together to make one big sorted list. Below\r\n   function takes O(n) extra space for recursive calls,\r\n    *\/\r\nstruct Node* SortedMerge(struct Node* a,struct Node* b)\r\n{\r\n    struct Node* result = NULL;\r\n \r\n    \/* Base cases *\/\r\n    if (a == NULL)\r\n        return (b);\r\n    else if (b == NULL)\r\n        return (a);\r\n \r\n    \/* Pick either a or b, and recur *\/\r\n    if (a->data <= b->data) {\r\n        result = a;\r\n        result->next = SortedMerge(a->next, b);\r\n    }\r\n    else {\r\n        result = b;\r\n        result->next = SortedMerge(a, b->next);\r\n    }\r\n \r\n    return result;\r\n}\r\n \r\n\/\/ The main function that takes an array of lists\r\n\/\/ arr[0..last] and generates the sorted output\r\nstruct Node* mergeKLists(struct Node* arr[], int last)\r\n{\r\n    \/\/ repeat until only one list is left\r\n    while (last != 0) {\r\n        int i = 0, j = last;\r\n \r\n        \/\/ (i, j) forms a pair\r\n        while (i < j) {\r\n            \/\/ merge List i with List j and store\r\n            \/\/ merged list in List i\r\n            arr[i] = SortedMerge(arr[i], arr[j]);\r\n \r\n            \/\/ consider next pair\r\n            i++, j--;\r\n \r\n            \/\/ If all pairs are merged, update last\r\n            if (i >= j)\r\n                last = j;\r\n        }\r\n    }\r\n \r\n    return arr[0];\r\n}\r\n \r\n\/\/ Utility function to create a new node.\r\nstruct Node* newNode(int data)\r\n{\r\n    struct Node* temp =\r\n           (struct Node*) malloc(sizeof(struct Node));\r\n    temp->data = data;\r\n    temp->next = NULL;\r\n    return temp;\r\n}\r\n \r\n\/\/ Driver program to test above functions\r\nint main()\r\n{\r\n    int k = 3; \/\/ Number of linked lists\r\n    int n = 4; \/\/ Number of elements in each list\r\n \r\n    \/\/ an array of pointers storing the head nodes\r\n    \/\/ of the linked lists\r\n    struct Node* arr[k];\r\n \r\n    arr[0] = newNode(1);\r\n    arr[0]->next = newNode(3);\r\n    arr[0]->next->next = newNode(5);\r\n    arr[0]->next->next->next = newNode(7);\r\n \r\n    arr[1] = newNode(2);\r\n    arr[1]->next = newNode(4);\r\n    arr[1]->next->next = newNode(6);\r\n    arr[1]->next->next->next = newNode(8);\r\n \r\n    arr[2] = newNode(0);\r\n    arr[2]->next = newNode(9);\r\n    arr[2]->next->next = newNode(10);\r\n    arr[2]->next->next->next = newNode(11);\r\n \r\n    \/\/ Merge all lists\r\n    struct Node* head = mergeKLists(arr, k - 1);\r\n \r\n    printList(head);\r\n \r\n    return 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\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_1807_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 data; \r\n    struct Node* next; \r\n}; \r\nstruct compare { \r\n    bool operator()(struct Node* a, struct Node* b) \r\n    { \r\n        return a->data > b->data; \r\n    } \r\n}; \r\n\r\nstruct Node* mergeKSortedLists(struct Node* arr[], int k) \r\n{ \r\n    struct Node *head = NULL, *last; \r\n    priority_queue<Node*, vector<Node*>, compare> pq; \r\n    for (int i = 0; i < k; i++) \r\n        if (arr[i] != NULL) \r\n            pq.push(arr[i]); \r\n\r\n    while (!pq.empty()) { \r\n        struct Node* top = pq.top(); \r\n        pq.pop(); \r\n        if (top->next != NULL)  \r\n            pq.push(top->next); \r\n        if (head == NULL) { \r\n            head = top; \r\n            last = top; \r\n        } \r\n\r\n        else {  \r\n            last->next = top; \r\n            last = top; \r\n        } \r\n    } \r\n    return head; \r\n} \r\nvoid printList(struct Node* head) \r\n{ \r\n    while (head != NULL) { \r\n        cout << head->data << \" \"; \r\n        head = head->next; \r\n    } \r\n} \r\nstruct Node* newNode(int data) \r\n{ \r\n    struct Node* new_node = new Node(); \r\n    new_node->data = data; \r\n    new_node->next = NULL; \r\n\r\n    return new_node; \r\n}  \r\nint main() \r\n{ \r\n    int k;cin>>k;\r\n    Node* arr[k]; \r\n    for(int i=0;i<k;i++)\r\n    {\r\n      int n;cin>>n;\r\n      int x;cin>>x;\r\n      arr[i]=newNode(x);\r\n      Node* head=arr[i];\r\n      for(int j=1;j<n;j++)\r\n      {\r\n        cin>>x;\r\n        head->next=newNode(x);\r\n        head=head->next;\r\n      }\r\n    }\r\n    struct Node* head = mergeKSortedLists(arr, k);\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_1807_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\nimport java.util.Arrays;\r\nimport java.util.Comparator;\r\nimport java.util.PriorityQueue;\r\nimport java.util.*;\r\nclass Node {\r\n    int data;\r\n    Node next;\r\n\r\n    public Node(int data) {\r\n        this.data = data;\r\n        this.next = null;\r\n    }\r\n}\r\n\r\npublic class Main\r\n{\r\n    public static void printList(Node node) {\r\n        while (node != null) {\r\n            System.out.print(node.data + \" \");\r\n            node = node.next;\r\n        }\r\n    }\r\n    public static Node mergeKLists(Node[] list, int k)\r\n    {\r\n        PriorityQueue<Node> pq;\r\n        pq = new PriorityQueue(Comparator.comparingInt(a -> ((Node) a).data));\r\n        pq.addAll(Arrays.asList(list).subList(0, k));\r\n        Node head = null, last = null;\r\n        while (!pq.isEmpty())\r\n        {\r\n            Node min = pq.poll();\r\n            if (head == null) {\r\n                head = last = min;\r\n            } else {\r\n                last.next = min;\r\n                last = min;\r\n            }\r\n            if (min.next != null) {\r\n                pq.add(min.next);\r\n            }\r\n        }\r\n        return head;\r\n    }\r\n\r\n    public static void main(String[] s) {\r\n        Scanner sc = new Scanner(System.in);\r\n        int k= sc.nextInt();\r\n        Node[] list = new Node[k];\r\n        for(int i=0;i<k;i++){\r\n            int n = sc.nextInt();\r\n          int x=sc.nextInt();\r\n\r\n        list[i] = new Node(x);\r\n        Node head=list[i];\r\n        for(int j=1;j<n;j++)\r\n        {\r\n          x=sc.nextInt();\r\n          head.next=new Node(x);\r\n          head=head.next;\r\n        }\r\n        }\r\n        Node headnew = mergeKLists(list, k);\r\n        printList(headnew);\r\n    }\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\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_1807_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\nimport heapq\r\nfrom heapq import heappop, heappush\r\nclass Node:\r\n    def __init__(self, data, next=None):\r\n        self.data = data\r\n        self.next = next\r\n \r\n    def __lt__(self, other):\r\n        return self.data < other.data\r\n \r\n \r\ndef printList(node):\r\n    while node:\r\n        print(node.data, end=' \u2014> ')\r\n        node = node.next\r\n \r\n    print('None')\r\n \r\n \r\ndef mergeKLists(lists):\r\n \r\n    pq = [x for x in lists]\r\n    heapq.heapify(pq)\r\n \r\n    head = last = None\r\n \r\n    while pq:\r\n \r\n        min = heappop(pq)\r\n \r\n        if head is None:\r\n            head = min\r\n            last = min\r\n        else:\r\n            last.next = min\r\n            last = min\r\n \r\n        if min.next:\r\n            heappush(pq, min.next)\r\n \r\n    return head\r\n \r\n \r\nif __name__ == '__main__':\r\n \r\n    k = 3\r\n \r\n    lists = [None] * k\r\n \r\n    lists[0] = Node(4)\r\n    lists[0].next = Node(6)\r\n    lists[0].next.next = Node(8)\r\n    lists[0].next.next.next = Node(10)\r\n    lists[0].next.next.next.next = Node(15)\r\n \r\n    lists[1] = Node(1)\r\n    lists[1].next = Node(5)\r\n    lists[1].next.next = Node(9)\r\n \r\n    lists[2] = Node(2)\r\n    lists[2].next = Node(3)\r\n    lists[2].next.next = Node(7)\r\n    lists[2].next.next.next = Node(11)\r\n \r\n    head = mergeKLists(lists)\r\n    printList(head)\r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\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_1807 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_1807 a\"),jQuery(\"#tab-content_1807\"));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>This blog discusses different approaches for figuring out how to merge k sorted lists. Every approach is important as knowing that will help you to understand the advantages and disadvantages of that approach. Targeting topics of data structures like Linked lists, Heaps, Priority queue will definitely help you to grab your dream job. For Practicing more questions, you can check out <a href=\"#\"><\/a>.<\/p>\n<h2>FAQ<\/h2>\n<p><strong>1. How do I merge two sorted lists?<\/strong><br \/>\nMerge two sorted linked lists using Dummy Nodes:<\/p>\n<ul>\n<li>First, make a dummy node for the new merged linked list.<\/li>\n<li>Now make two pointers, one will point to list1 and another will point to list2.<\/li>\n<li>Now traverse the lists till one of them gets exhausted.<\/li>\n<\/ul>\n<p><strong>2. Which companies have recently asked how to merge k sorted lists?<\/strong><br \/>\nSamsung, SquadStack, Amazon, and Josh Technologies in their recent technical interviews have asked this question.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we will discuss three different approaches to merge k sorted lists. Merging k sorted linked lists is a challenging topic and conquering it will make your data structures more efficient. Let\u2019s discuss how to merge k sorted lists. How to Merge K Sorted Linked List? Yor are given K sorted linked lists. [&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-1806","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>Merge K Sorted Linked Lists | Linked List | Prepbytes<\/title>\n<meta name=\"description\" content=\"Yor Are Given K Sorted Linked Lists. You Have to Merge K Sorted Linked Lists Into One Sorted List. the Size of the Linked List Maybe Different.\" \/>\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\/merge-k-sorted-linked-lists\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Merge K Sorted Linked Lists | Linked List | Prepbytes\" \/>\n<meta property=\"og:description\" content=\"Yor Are Given K Sorted Linked Lists. You Have to Merge K Sorted Linked Lists Into One Sorted List. the Size of the Linked List Maybe Different.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/\" \/>\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=\"2020-06-11T18:01:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-28T07:15:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645174449305-Article_399.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\/merge-k-sorted-linked-lists\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"MERGE K SORTED LINKED LISTS\",\"datePublished\":\"2020-06-11T18:01:04+00:00\",\"dateModified\":\"2022-11-28T07:15:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/\"},\"wordCount\":406,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645174449305-Article_399.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/\",\"name\":\"Merge K Sorted Linked Lists | Linked List | Prepbytes\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645174449305-Article_399.png\",\"datePublished\":\"2020-06-11T18:01:04+00:00\",\"dateModified\":\"2022-11-28T07:15:45+00:00\",\"description\":\"Yor Are Given K Sorted Linked Lists. You Have to Merge K Sorted Linked Lists Into One Sorted List. the Size of the Linked List Maybe Different.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645174449305-Article_399.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645174449305-Article_399.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/#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\":\"MERGE K SORTED LINKED LISTS\"}]},{\"@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":"Merge K Sorted Linked Lists | Linked List | Prepbytes","description":"Yor Are Given K Sorted Linked Lists. You Have to Merge K Sorted Linked Lists Into One Sorted List. the Size of the Linked List Maybe Different.","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\/merge-k-sorted-linked-lists\/","og_locale":"en_US","og_type":"article","og_title":"Merge K Sorted Linked Lists | Linked List | Prepbytes","og_description":"Yor Are Given K Sorted Linked Lists. You Have to Merge K Sorted Linked Lists Into One Sorted List. the Size of the Linked List Maybe Different.","og_url":"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2020-06-11T18:01:04+00:00","article_modified_time":"2022-11-28T07:15:45+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645174449305-Article_399.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\/merge-k-sorted-linked-lists\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"MERGE K SORTED LINKED LISTS","datePublished":"2020-06-11T18:01:04+00:00","dateModified":"2022-11-28T07:15:45+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/"},"wordCount":406,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645174449305-Article_399.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/","url":"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/","name":"Merge K Sorted Linked Lists | Linked List | Prepbytes","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645174449305-Article_399.png","datePublished":"2020-06-11T18:01:04+00:00","dateModified":"2022-11-28T07:15:45+00:00","description":"Yor Are Given K Sorted Linked Lists. You Have to Merge K Sorted Linked Lists Into One Sorted List. the Size of the Linked List Maybe Different.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645174449305-Article_399.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645174449305-Article_399.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/merge-k-sorted-linked-lists\/#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":"MERGE K SORTED LINKED LISTS"}]},{"@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\/1806","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=1806"}],"version-history":[{"count":8,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/1806\/revisions"}],"predecessor-version":[{"id":10781,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/1806\/revisions\/10781"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=1806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=1806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=1806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}