{"id":3819,"date":"2021-08-12T06:44:39","date_gmt":"2021-08-12T06:44:39","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=3819"},"modified":"2022-11-04T10:23:58","modified_gmt":"2022-11-04T10:23:58","slug":"union-and-intersection-of-two-linked-lists","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/","title":{"rendered":"Union and Intersection of two Linked Lists"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926688924-119.Union%20and%20Intersection%20of%20two%20Linked%20Lists_Artboard%202.png\" alt=\"\" \/><\/p>\n<h3>Introduction<\/h3>\n<p>In the below article, we are going to see how Union is going to work with the linked lists. Generally, if we talk about the union of two linked lists, then there will be a union list which will contain all the elements from both of the lists but common elements will appear once in the union list. Let&#8217;s get into the approach of union of two linked lists and intersection of two linked lists <\/p>\n<\/p>\n<h3>Problem Statement of union of two linked lists and how to find the intersection of two linked lists.<\/h3>\n<p>In this question, we are given two singly-linked lists. We have to find the Union and Intersection of the given lists.<\/p>\n<h3>Problem Statement Understanding for union and intersection of two linked lists<br \/>\n<\/h3>\n<p><strong>Union<\/strong> &#8211; All the elements that are in at least one of the two lists.<\/p>\n<p><strong>Intersection<\/strong> &#8211; Only the elements which are present in both lists.<\/p>\n<p><strong>Suppose the lists are:<\/strong><\/p>\n<p>L1 : 1 &#8211; &gt; 2 &#8211; &gt; 3<\/p>\n<p>L2 : 2- &gt; 3 &#8211; &gt; 4<\/p>\n<p>So, the union (elements that are in atleast one of the two lists) will be:<\/p>\n<p><strong>Union List:<\/strong> 1 &#8211; &gt; 2 &#8211; &gt; 3 &#8211; &gt; 4<\/p>\n<p>The intersection (elements that are present in both the lists) will be:<\/p>\n<p><strong>Intersection List:<\/strong> 2 &#8211; &gt; 3<\/p>\n<p><strong>Input<\/strong><\/p>\n<p>L1 : <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Union-and-Intersection-of-two-Linked-Lists-input-01.png\" alt=\"\" \/><\/p>\n<p>L2 :<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Union-and-Intersection-of-two-Linked-Lists-input2-01.png\" alt=\"\" \/><\/p>\n<p><strong>Output<\/strong><\/p>\n<p>Intersection List: 2 &#8211; &gt; 3<\/p>\n<p>Union List: 1 &#8211; &gt; 2 &#8211; &gt; 3 &#8211; &gt; 4<\/p>\n<p><strong>Explanation:<\/strong> As the common elements of L1 and L2 are 2 and 3, they appear in the Intersection list. For the Union List, all the elements of L1 and L2 are considered, but no repetitions. So that&#8217;s why 2 and 3 are only present once in the union list.<\/p>\n<p>While creating the lists, we do not have to worry about the order of the elements. They can be in any order.<\/p>\n<p>This question is a pretty easy one. The first approach that comes to mind is to pick one element from one list, then traverse through the other list, and keep adding to output lists if necessary. But, can we do better? Yes. We can use hashing. Let us have a glance at the approaches<\/p>\n<h3>Approach (Nested List Traversal)for union of two linked lists<\/h3>\n<p>The approach is going to be pretty simple. <\/p>\n<p><strong>Intersection List<\/strong> &#8211; Create an empty result list. Traverse through the first list, and look for every element in the second list. If the element is present in the second list, then add that element to the result list.<\/p>\n<p><strong>Union List<\/strong> &#8211; Create an empty result list. Traverse through the first list and add all of its elements to the result list. Now, traverse through the second list. If an element of the second list is already present in the result list, then do not insert it into the result list, otherwise insert it.<\/p>\n<p><strong>Time Complexity of union of two linked lists<\/strong> &#8211; O(m*n), where m and n are the sizes of the two input lists.<\/p>\n<p><strong>Space Complexity union of two linked lists<\/strong> &#8211; O(1), as only temporary nodes are being created for list traversal.<\/p>\n<p>There is another approach that uses hashing. The time complexity of that approach is better than the time complexity of this approach, so let us have a look at that approach as well.<\/p>\n<h3>Approach (Hashing)for union and intersection of two linked lists<br \/>\n  <\/h3>\n<p>This approach is going to use hashing. A very simple application of hashing.<\/p>\n<p><strong>Union List<\/strong> &#8211; Create an empty result list and an empty hash table. Traverse both the linked lists one by one. Insert every element in the hash table. Now, we will traverse through the hash table and insert all the elements in the new list. As a hash table only stores unique keys, we will automatically get the union list.<\/p>\n<p><strong>Intersection List<\/strong> &#8211; Create an empty result list and an empty hash table. Traverse through both the list, and increment the frequency of every element. Now, we will traverse through the hash table, and only the elements whose frequency is 2 will be inserted in the result list. As frequency 2 ensures that the element is present in both lists.<\/p>\n<h3>Algorithm for union and intersection of two linked lists<br \/>\n<\/h3>\n<p><strong>Union List<\/strong><\/p>\n<ul>\n<li>Create an empty list and an empty map.<\/li>\n<li>Insert all the elements of both the lists in the map as key and their frequencies as values.<\/li>\n<li>Traverse through the map and keep pushing all the elements of the map in the result list.<\/li>\n<li>As a map only stores unique values, we will automatically get the union.<\/li>\n<li>Return the result list.<\/li>\n<\/ul>\n<p><strong>Intersection List<\/strong><\/p>\n<ul>\n<li>Create an empty list and an empty map.<\/li>\n<li>Insert all the elements of both the lists in the map as key, and their frequencies as values<\/li>\n<li>Traverse through the map and add all those elements in the result list, whose frequency is two.<\/li>\n<li>As the frequency is two, this means that the element is present in both lists. Here, we are assuming that there are no repetitions in the given lists.<\/li>\n<li>Return the result list.<\/li>\n<\/ul>\n<h3>Dry Run for union and intersection of two linked lists<br \/>\n <\/h3>\n<p><strong>Union List<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/union-01-1.png\" alt=\"\" \/><\/p>\n<p><strong>Intersection List<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/intersection-01-1.png\" alt=\"\" \/><\/p>\n<h3>Code Implementation for union and intersection of two linked lists<br \/>\n<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_3818 {\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_3818 .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_3818 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_3818 .wpsm_nav-tabs > li.active > a, #tab_container_3818 .wpsm_nav-tabs > li.active > a:hover, #tab_container_3818 .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_3818 .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_3818 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_3818 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_3818 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_3818 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_3818 .wpsm_nav-tabs > li > a:hover , #tab_container_3818 .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_3818 .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_3818 .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_3818 .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_3818 .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_3818 .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_3818 .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_3818 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_3818 .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_3818 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_3818 .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_3818 .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_3818\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_3818\">\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_3818_1\" aria-controls=\"tabs_desc_3818_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_3818_2\" aria-controls=\"tabs_desc_3818_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>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_3818_3\" aria-controls=\"tabs_desc_3818_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>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_3818\">\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_3818_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"cpp\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include &lt;bits stdc++.h=&quot;&quot;&gt;\r\nusing namespace std;\r\n\r\nstruct Node {\r\n    int data;\r\n    struct Node* next;\r\n};\r\n\r\nvoid push(struct Node** head_ref, int new_data)\r\n{\r\n\r\n    struct Node* new_node = (struct Node*)malloc(\r\n        sizeof(struct Node));\r\n\r\n    new_node-&gt;data = new_data;\r\n\r\n    new_node-&gt;next = (*head_ref);\r\n\r\n    (*head_ref) = new_node;\r\n}\r\n\r\nvoid storeEle(struct Node* head1, struct Node* head2,\r\n              unordered_map&lt;int, int=&quot;&quot;&gt;&amp; eleOcc)\r\n{\r\n    struct Node* ptr1 = head1;\r\n    struct Node* ptr2 = head2;\r\n\r\n    while (ptr1 != NULL || ptr2 != NULL) {\r\n\r\n        if (ptr1 != NULL) {\r\n            eleOcc[ptr1-&gt;data]++;\r\n            ptr1 = ptr1-&gt;next;\r\n        }\r\n  \r\n\r\n        if (ptr2 != NULL) {\r\n            eleOcc[ptr2-&gt;data]++;\r\n            ptr2 = ptr2-&gt;next;\r\n        }\r\n    }\r\n}\r\n\r\nstruct Node* getUnion(unordered_map&lt;int, int=&quot;&quot;&gt; eleOcc)\r\n{\r\n    struct Node* result = NULL;\r\n\r\n    for (auto it = eleOcc.begin(); it != eleOcc.end(); it++)\r\n        push(&amp;result, it-&gt;first);\r\n  \r\n    return result;\r\n}\r\n\r\nstruct Node* getIntersection(unordered_map&lt;int, int=&quot;&quot;&gt;eleOcc)\r\n{\r\n    struct Node* result = NULL;\r\n\r\n    for (auto it = eleOcc.begin();\r\n         it != eleOcc.end(); it++)\r\n        if (it-&gt;second == 2)\r\n            push(&amp;result, it-&gt;first);\r\n\r\n    return result;\r\n}\r\n\r\nvoid printList(struct Node* node)\r\n{\r\n    while (node != NULL) {\r\n        printf(&quot;%d &quot;, node-&gt;data);\r\n        node = node-&gt;next;\r\n    }\r\n}\r\n\r\nvoid printUnionIntersection(Node* head1, Node* head2)\r\n{\r\n    unordered_map&lt;int, int=&quot;&quot;&gt; eleOcc;\r\n    storeEle(head1, head2, eleOcc);\r\n  \r\n    Node* intersection_list = getIntersection(eleOcc);\r\n    Node* union_list = getUnion(eleOcc);\r\n  \r\n    printf(&quot;&#92;nIntersection list is &#92;n&quot;);\r\n    printList(intersection_list);\r\n  \r\n    printf(&quot;&#92;nUnion list is &#92;n&quot;);\r\n    printList(union_list);\r\n}\r\n\r\nint main()\r\n{\r\n    struct Node* head1 = NULL;\r\n    struct Node* head2 = NULL;\r\n\r\n    push(&amp;head1, 1);\r\n    push(&amp;head1, 2);\r\n    push(&amp;head1, 3);\r\n\r\n\r\n    push(&amp;head2, 2);\r\n    push(&amp;head2, 3);\r\n    push(&amp;head2, 4);\r\n  \r\n    printf(&quot;First list is &#92;n&quot;);\r\n    printList(head1);\r\n  \r\n    printf(&quot;&#92;nSecond list is &#92;n&quot;);\r\n    printList(head2);\r\n  \r\n    printUnionIntersection(head1, head2);\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_3818_2\">\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\npublic class LinkedList {\r\n    Node head; \r\n\r\n    class Node {\r\n        int data;\r\n        Node next;\r\n        Node(int d)\r\n        {\r\n            data = d;\r\n            next = null;\r\n        }\r\n    }\r\n\r\n    void getUnion(Node head1, Node head2)\r\n    {\r\n        Node x1 = head1, x2 = head2;\r\n\r\n        while (x1 != null) {\r\n            push(x1.data);\r\n            x1 = x1.next;\r\n        }\r\n\r\n        while (x2 != null) {\r\n            if (!isPresent(head, x2.data))\r\n                push(x2.data);\r\n            x2 = x2.next;\r\n        }\r\n    }\r\n\r\n    void getIntersection(Node head1, Node head2)\r\n    {\r\n        Node result = null;\r\n        Node x1 = head1;\r\n\r\n        while (x1 != null) {\r\n            if (isPresent(head2, x1.data))\r\n                push(x1.data);\r\n            x1 = x1.next;\r\n        }\r\n    }\r\n\r\n    void printList()\r\n    {\r\n        Node temp = head;\r\n        while (temp != null) {\r\n            System.out.print(temp.data + &quot; &quot;);\r\n            temp = temp.next;\r\n        }\r\n        System.out.println();\r\n    }\r\n\r\n    void push(int new_data)\r\n    {\r\n\r\n        Node new_node = new Node(new_data);\r\n\r\n        new_node.next = head;\r\n\r\n        head = new_node;\r\n    }\r\n\r\n    boolean isPresent(Node head, int data)\r\n    {\r\n        Node t = head;\r\n        while (t != null) {\r\n            if (t.data == data)\r\n                return true;\r\n            t = t.next;\r\n        }\r\n        return false;\r\n    }\r\n\r\n    public static void main(String args[])\r\n    {\r\n        LinkedList llist1 = new LinkedList();\r\n        LinkedList llist2 = new LinkedList();\r\n        LinkedList unin = new LinkedList();\r\n        LinkedList intersecn = new LinkedList();\r\n\r\n        llist1.push(1);\r\n        llist1.push(2);\r\n        llist1.push(3);\r\n\r\n        llist2.push(2);\r\n        llist2.push(3);\r\n        llist2.push(4);\r\n\r\n        intersecn.getIntersection(llist1.head, llist2.head);\r\n        unin.getUnion(llist1.head, llist2.head);\r\n\r\n        System.out.println(&quot;First List is&quot;);\r\n        llist1.printList();\r\n\r\n        System.out.println(&quot;Second List is&quot;);\r\n        llist2.printList();\r\n\r\n        System.out.println(&quot;Intersection List is&quot;);\r\n        intersecn.printList();\r\n\r\n        System.out.println(&quot;Union List is&quot;);\r\n        unin.printList();\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_3818_3\">\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# Python code for finding union and intersection of linkedList\r\n\r\n\r\nclass linkedList:\r\n\tdef __init__(self):\r\n\t\tself.head = None\r\n\t\tself.tail = None\r\n\r\n\tdef insert(self, data):\r\n\t\tif self.head is None:\r\n\t\t\tself.head = Node(data)\r\n\t\t\tself.tail = self.head\r\n\t\telse:\r\n\t\t\tself.tail.next = Node(data)\r\n\t\t\tself.tail = self.tail.next\r\n\r\n\r\nclass Node:\r\n\tdef __init__(self, data):\r\n\t\tself.data = data\r\n\t\tself.next = None\r\n\r\n# return the head of new list containing the intersection of 2 linkedList\r\n\r\n\r\ndef findIntersection(head1, head2):\r\n\t# creating a map\r\n\thashmap = {}\r\n\r\n\t# traversing on first list\r\n\twhile(head1 != None):\r\n\t\tdata = head1.data\r\n\t\tif(data not in hashmap.keys()):\r\n\t\t\thashmap[data] = 1\r\n\t\thead1 = head1.next\r\n\r\n\t# making a new linkedList\r\n\tans = linkedList()\r\n\twhile(head2 != None):\r\n\t\tdata = head2.data\r\n\t\tif(data in hashmap.keys()):\r\n\t\t\t# adding data to new list\r\n\t\t\tans.insert(data)\r\n\t\thead2 = head2.next\r\n\treturn ans.head\r\n\r\n# return the head of new list containing the union of 2 linkedList\r\n\r\n\r\ndef union(head1, head2):\r\n\t# creating a map\r\n\thashmap = {}\r\n\r\n\t# traversing on first list\r\n\twhile(head1 != None):\r\n\t\tdata = head1.data\r\n\t\tif(data not in hashmap.keys()):\r\n\t\t\thashmap[data] = 1\r\n\t\thead1 = head1.next\r\n\r\n\twhile(head2 != None):\r\n\t\tdata = head2.data\r\n\t\tif(data not in hashmap.keys()):\r\n\t\t\thashmap[data] = 1\r\n\t\thead2 = head2.next\r\n\r\n\t# making a new linkedList\r\n\tans = linkedList()\r\n\r\n\t# traverse on hashmap\r\n\tfor key, value in hashmap.items():\r\n\t\tans.insert(key)\r\n\r\n\treturn ans.head\r\n\r\n\r\ndef printList(head):\r\n\twhile head:\r\n\t\tprint(head.data, end=' ')\r\n\t\thead = head.next\r\n\tprint()\r\n\r\n\r\nif __name__ == '__main__':\r\n\r\n\t# first list\r\n\tll1 = linkedList()\r\n\tll1.insert(1)\r\n\tll1.insert(2)\r\n\tll1.insert(3)\r\n\r\n\t# second list\r\n\tll2 = linkedList()\r\n\tll2.insert(2)\r\n\tll2.insert(3)\r\n\tll2.insert(4)\r\n\t\r\n\tprint(&quot;First list is &quot;)\r\n\tprintList(ll1.head)\r\n\r\n\tprint(&quot;Second list is &quot;)\r\n\tprintList(ll2.head)\r\n\r\n\tprint(&quot;Intersection list is&quot;)\r\n\tprintList(findIntersection(ll1.head, ll2.head))\r\n\r\n\tprint(&quot;Union list is &quot;)\r\n\tprintList(union(ll1.head, ll2.head))\r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_3818 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_3818 a\"),jQuery(\"#tab-content_3818\"));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>First List is :<\/p>\n<p>3 2 1 <\/p>\n<p>Second List is :<\/p>\n<p>4 3 2 <\/p>\n<p>Intersection List is :<\/p>\n<p>2 3 <\/p>\n<p>Union List is :<\/p>\n<p>4 1 2 3<\/p>\n<p><strong>Space Complexity:<\/strong> O(m+n), the space needed for the map (where m and n are the sizes of the given lists).<\/p>\n<p>So, in this article, we have seen a detailed approach  and algorithm for the union and intersection of two linked lists .This is an easy problem with many approaches. Knowing this efficient approach is very important for coding interviews. 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<h2> FAQs <\/h2>\n<ol>\n<li><strong>Does the order matter in linked lists?<\/strong><\/li>\n<p>The order in the linked lists doesn\u2019t matter in the output list.<\/p>\n<li><strong>How are structures different from the unions? <\/strong><\/li>\n<p>Structures are generally used to store distinct values in unique memory locations whereas unions manage the memory efficiently.<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In the below article, we are going to see how Union is going to work with the linked lists. Generally, if we talk about the union of two linked lists, then there will be a union list which will contain all the elements from both of the lists but common elements will appear once [&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-3819","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>Learn how to Union and Intersection of two Linked Lists<\/title>\n<meta name=\"description\" content=\"Learn the most efficient way to find the union and intersection of two linked lists. This blog explains the most efficient approach to find the union and intersection of two linked lists.\" \/>\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\/union-and-intersection-of-two-linked-lists\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn how to Union and Intersection of two Linked Lists\" \/>\n<meta property=\"og:description\" content=\"Learn the most efficient way to find the union and intersection of two linked lists. This blog explains the most efficient approach to find the union and intersection of two linked lists.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-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=\"2021-08-12T06:44:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-04T10:23:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926688924-119.Union%20and%20Intersection%20of%20two%20Linked%20Lists_Artboard%202.png\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Union and Intersection of two Linked Lists\",\"datePublished\":\"2021-08-12T06:44:39+00:00\",\"dateModified\":\"2022-11-04T10:23:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/\"},\"wordCount\":1001,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926688924-119.Union%20and%20Intersection%20of%20two%20Linked%20Lists_Artboard%202.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/\",\"name\":\"Learn how to Union and Intersection of two Linked Lists\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926688924-119.Union%20and%20Intersection%20of%20two%20Linked%20Lists_Artboard%202.png\",\"datePublished\":\"2021-08-12T06:44:39+00:00\",\"dateModified\":\"2022-11-04T10:23:58+00:00\",\"description\":\"Learn the most efficient way to find the union and intersection of two linked lists. This blog explains the most efficient approach to find the union and intersection of two linked lists.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926688924-119.Union%20and%20Intersection%20of%20two%20Linked%20Lists_Artboard%202.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926688924-119.Union%20and%20Intersection%20of%20two%20Linked%20Lists_Artboard%202.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-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\":\"Union and Intersection of two 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":"Learn how to Union and Intersection of two Linked Lists","description":"Learn the most efficient way to find the union and intersection of two linked lists. This blog explains the most efficient approach to find the union and intersection of two linked lists.","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\/union-and-intersection-of-two-linked-lists\/","og_locale":"en_US","og_type":"article","og_title":"Learn how to Union and Intersection of two Linked Lists","og_description":"Learn the most efficient way to find the union and intersection of two linked lists. This blog explains the most efficient approach to find the union and intersection of two linked lists.","og_url":"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-08-12T06:44:39+00:00","article_modified_time":"2022-11-04T10:23:58+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926688924-119.Union%20and%20Intersection%20of%20two%20Linked%20Lists_Artboard%202.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\/union-and-intersection-of-two-linked-lists\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Union and Intersection of two Linked Lists","datePublished":"2021-08-12T06:44:39+00:00","dateModified":"2022-11-04T10:23:58+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/"},"wordCount":1001,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926688924-119.Union%20and%20Intersection%20of%20two%20Linked%20Lists_Artboard%202.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/","url":"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/","name":"Learn how to Union and Intersection of two Linked Lists","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926688924-119.Union%20and%20Intersection%20of%20two%20Linked%20Lists_Artboard%202.png","datePublished":"2021-08-12T06:44:39+00:00","dateModified":"2022-11-04T10:23:58+00:00","description":"Learn the most efficient way to find the union and intersection of two linked lists. This blog explains the most efficient approach to find the union and intersection of two linked lists.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-linked-lists\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926688924-119.Union%20and%20Intersection%20of%20two%20Linked%20Lists_Artboard%202.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926688924-119.Union%20and%20Intersection%20of%20two%20Linked%20Lists_Artboard%202.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/union-and-intersection-of-two-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":"Union and Intersection of two 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\/3819","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=3819"}],"version-history":[{"count":7,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/3819\/revisions"}],"predecessor-version":[{"id":10337,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/3819\/revisions\/10337"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=3819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=3819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=3819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}