{"id":5841,"date":"2021-10-25T11:20:59","date_gmt":"2021-10-25T11:20:59","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=5841"},"modified":"2022-11-28T09:36:46","modified_gmt":"2022-11-28T09:36:46","slug":"find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/","title":{"rendered":"Find a triplet from three linked lists with a sum equal to a given number"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012237824-Article_205.png\" alt=\"\" \/><\/p>\n<p>This article will discuss in detail how to find a triplet from three linked lists with a sum equal to a given number. Linked list is a dominating topic when we look at the data structures and having a good grip on linked list will help in clearing the interviews for the tech interviews. Let\u2019s get back to our topic and see how to find a triplet from three linked lists with a sum equal to a given number.<\/p>\n<h2>How to find a triplet from three linked lists with a sum equal to a given number<\/h2>\n<p>We will be given three different linked lists and an integer as input. Now, we need to find whether there is a triplet (one from each list) that sums up to the given integer.<\/p>\n<p>To understand the problem statement, let us take examples.<\/p>\n<p>If the linked lists given to us are 3\u21928\u21921\u21925\u2192NULL, 6\u21922\u21928\u2192NULL, and 11\u21924\u21922\u2192NULL, and the target = 14. Then, according to the problem statement:<\/p>\n<ul>\n<li>We need to find three Nodes (one from each list) such that they sum up to 14.<\/li>\n<li>If we select <strong>8<\/strong> from the <strong>first list<\/strong>, <strong>2<\/strong> from the <strong>second list<\/strong> and <strong>4<\/strong> from the <strong>third list<\/strong>, we will get the sum equal to the <strong>target=14<\/strong>.<\/li>\n<li>The required triplet will be <strong>(8,2,4)<\/strong>.<\/li>\n<\/ul>\n<p>At this point, we have understood the problem statement. Now we will try to formulate an approach for this problem.<\/p>\n<p>Before moving to the approach section, try to think about how you can approach this problem.<\/p>\n<ul>\n<li>If stuck, no problem, we will thoroughly see how we can approach this problem in the next section.<\/li>\n<\/ul>\n<p>Let\u2019s move to the approach section.<\/p>\n<h2>Approach 1<\/h2>\n<p>The naive approach that comes to our mind is to first select a node from the first list. Then for each node of the first list, we select a node from the second list, and for each selected node of the second list, we select a node in the third list, and then we check if the sum of the 3 nodes selected is equal to target or not. If the sum is equal to the target, we have our required triplet.<\/p>\n<p><strong>Time Complexity:<\/strong> O(n<sup>3<\/sup>) , n is the number of nodes in a list.<\/p>\n<p>The above approach gives the correct result, but its time complexity is high. Can we reduce the time complexity? Let us find out If we can do so in the below approach.<\/p>\n<h2>Approach 2<\/h2>\n<ul>\n<li>First, we need to sort the second and third lists (the second list will be sorted in ascending order and the third list in descending order), so that we could be sure whether moving forward or backward in the lists is going to increase or decrease the sum.<\/li>\n<li>Now, we need to fix a node in the first list and for each node, we need to perform the below steps.<\/li>\n<li>Calculate the sum of all three-pointers present at different positions on each list.<\/li>\n<li>If the sum is greater than the target, then we need to decrease the sum, so we need to move forward in the third list (if you visualize carefully, you can see that moving forward in the third list will decrease the sum, because the third list is sorted in descending order).<\/li>\n<li>Else If the sum is smaller than the target, we need to move forward in the second list to increase our sum (as the second list is sorted in ascending order).<\/li>\n<li>If the sum is equal, then we can easily print the triplet and show that we have found one triplet in the three given lists.<\/li>\n<\/ul>\n<p>To see the above approach in more detail, move to the algorithm section.<\/p>\n<h2>Algorithm<\/h2>\n<p>1) First, sort the second list in ascending order and the third list in descending order.<br \/>\n2) Initialize a pointer <strong>a<\/strong> with head of <strong>first list<\/strong>.<br \/>\n3) Run a while loop till <strong>a<\/strong> is not NULL and inside the loop:<\/p>\n<ul>\n<li>Initialize pointer <strong>b<\/strong> and <strong>c<\/strong> with <strong>head of second and third list<\/strong>, respectively.<\/li>\n<li>Run a while loop till <strong>b<\/strong> and <strong>c<\/strong> are not NULL.\n<ul>\n<li>Initialize variable <strong>sum<\/strong> as the sum of values pointed by pointers <strong>a<\/strong>,<strong>b<\/strong>, and <strong>c<\/strong>.<\/li>\n<li>If the <strong>sum<\/strong> is equal to the <strong>target<\/strong>, print the values pointed by <strong>a<\/strong>,<strong>b<\/strong>, and <strong>c<\/strong> and return from the function.<\/li>\n<li>If the <strong>sum<\/strong> is less than the <strong>target<\/strong>, move forward <strong>b<\/strong> by one node. Else, move forward <strong>c<\/strong> by one node.<\/li>\n<\/ul>\n<\/li>\n<li>Move forward <strong>a<\/strong> by one node.<\/li>\n<\/ul>\n<p><strong>Note:<\/strong> For simplicity, in dry run and code implementation, we took second and third linked lists, which are already sorted in ascending and descending order, respectively. If you want to know how to sort a linked list, please feel free to refer to this <a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/c-program-for-merge-sort-for-linked-lists\/\">article<\/a> for sorting related concepts of linked list. Also, inside the code implementation, we haven&#8217;t provided the sorting function (function to sort the linked list); if you want to take unsorted linked lists, please sort them in proper format (the second list will be sorted in ascending order and the third list in descending order) using code from above-mentioned article, before passing them to <strong>isSumSorted()<\/strong> function in the code.<\/p>\n<h3>Dry Run<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/p_1-4.jpg\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/p_2-5.jpg\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/p_3-3.jpg\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/p_4-1.jpg\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/p_5.jpg\" alt=\"\" \/><\/p>\n<p>## Code Implementation<br \/>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_5842 {\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_5842 .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_5842 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_5842 .wpsm_nav-tabs > li.active > a, #tab_container_5842 .wpsm_nav-tabs > li.active > a:hover, #tab_container_5842 .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_5842 .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_5842 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_5842 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_5842 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_5842 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_5842 .wpsm_nav-tabs > li > a:hover , #tab_container_5842 .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_5842 .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_5842 .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_5842 .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_5842 .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_5842 .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_5842 .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_5842 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5842 .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_5842 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5842 .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_5842 .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_5842\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_5842\">\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_5842_1\" aria-controls=\"tabs_desc_5842_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_5842_2\" aria-controls=\"tabs_desc_5842_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_5842_3\" aria-controls=\"tabs_desc_5842_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_5842_4\" aria-controls=\"tabs_desc_5842_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_5842\">\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_5842_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"c\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include&lt;stdio.h&gt;\r\n#include&lt;stdlib.h&gt;\r\n#include&lt;stdbool.h&gt;\r\n \r\n\/* Link list node *\/\r\nstruct Node\r\n{\r\n    int data;\r\n    struct Node* next;\r\n};\r\n\r\nvoid isSumSorted(struct Node *first,struct Node *second,struct Node *third, int target)\r\n{\r\n    struct Node *a = first;\r\n \r\n    \/\/Select a node in first list and\r\n    \/\/traverse the other two lists for\r\n    \/\/each selected node\r\n    while (a != NULL)\r\n    {\r\n       struct Node *b = second;\r\n        struct Node *c = third;\r\n \r\n        \/\/select posssible pairs of nodes\r\n        \/\/from second and thirs list\r\n        \/\/(one from each list)\r\n        while (b != NULL &amp;&amp; c != NULL)\r\n        {\r\n            \/\/ if sum is equal to our target\r\n            int sum = a-&gt;data + b-&gt;data + c-&gt;data;\r\n            if (sum == target)\r\n            {\r\n            printf (&quot;Triplet Found: %d %d %d &quot;, a-&gt;data,\r\n                                         b-&gt;data, c-&gt;data);\r\n            return;\r\n            }\r\n \r\n            \/\/ If sum is less than target\r\n            else if (sum &lt; target)\r\n                b = b-&gt;next;\r\n            else\r\n                c = c-&gt;next;\r\n        }\r\n        a = a-&gt;next; \/\/ Move ahead in list a\r\n    }\r\n \r\n    printf( &quot;No such triplet&quot;);\r\n    return;\r\n}\r\n\r\nstruct Node* newNode(int x)\r\n{\r\n    struct Node* node = malloc(sizeof(struct Node*));\r\n    node-&gt;data = x;\r\n    node-&gt;next = NULL;\r\n    return node;\r\n}\r\nint main(void){\r\n    struct Node* first = NULL;\r\n    first = newNode(3);\r\n    first-&gt;next = newNode(8);\r\n    first-&gt;next-&gt;next = newNode(1);\r\n    struct Node* second = NULL;\r\n    second = newNode(2);\r\n    second-&gt;next = newNode(6);\r\n    second-&gt;next-&gt;next = newNode(8);\r\n    struct Node* third = NULL;\r\n    third = newNode(11);\r\n    third-&gt;next = newNode(4);\r\n    third-&gt;next-&gt;next = newNode(2);\r\n    isSumSorted(first,second,third,14);  \r\n}                                               \r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_5842_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=&quot;&quot;&gt;\r\nusing namespace std;\r\nclass Node{\r\n    public:\r\n    int data;\r\n    Node* next;\r\n    Node(int x){\r\n        data = x;\r\n        next = NULL;\r\n    }\r\n};\r\n\r\nvoid isSumSorted(Node *first, Node *second,Node *third, int target)\r\n{\r\n    Node *a = first;\r\n \r\n    \/\/Select a node in first list and\r\n    \/\/traverse the other two lists for\r\n    \/\/each selected node\r\n    while (a != NULL)\r\n    {\r\n        Node *b = second;\r\n        Node *c = third;\r\n \r\n        \/\/select posssible pairs of nodes\r\n        \/\/from second and thirs list\r\n        \/\/(one from each list)\r\n        while (b != NULL &amp;&amp; c != NULL)\r\n        {\r\n            \/\/ if sum is equal to our target\r\n            int sum = a-&gt;data + b-&gt;data + c-&gt;data;\r\n            if (sum == target)\r\n            {\r\n            cout &lt;&lt; &quot;Triplet Found: &quot; &lt;&lt; a-&gt;data &lt;&lt; &quot; &quot; &lt;&lt;b-&gt;data &lt;&lt; &quot; &quot; &lt;&lt; c-&gt;data;\r\n            return;\r\n            }\r\n \r\n            \/\/ If sum is less than target\r\n            else if (sum &lt; target)\r\n                b = b-&gt;next;\r\n            else\r\n                c = c-&gt;next;\r\n        }\r\n        a = a-&gt;next; \/\/ Move ahead in list a\r\n    }\r\n \r\n    cout &lt;&lt; &quot;No such triplet&quot;;\r\n    return;\r\n}\r\n\r\nint main(void){\r\n    Node* first = NULL;\r\n    first = new Node(3);\r\n    first-&gt;next = new Node(8);\r\n    first-&gt;next-&gt;next = new Node(1);\r\n\r\n    Node* second = NULL;\r\n    second = new Node(2);\r\n    second-&gt;next = new Node(6);\r\n    second-&gt;next-&gt;next = new Node(8);\r\n\r\n    Node* third = NULL;\r\n    third = new Node(11);\r\n    third-&gt;next = new Node(4);\r\n    third-&gt;next-&gt;next = new Node(2);\r\n\r\n    isSumSorted(first,second,third,14);  \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_5842_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 Triplet\r\n{\r\n    Node head; \r\n\r\n    class Node\r\n    {\r\n        int data;\r\n        Node next;\r\n        Node(int d) {data = d; next = null; }\r\n    }\r\n    boolean isSumSorted(Triplet llist1, Triplet llist2, Triplet llist3,int givenNumber)\r\n    {\r\n        Node a = llist1.head;\r\n\r\n        while (a != null)\r\n        {\r\n            Node b = llist2.head;\r\n            Node c = llist3.head;\r\n\r\n            \/\/ for every node in la pick 2 nodes from lb and lc\r\n            while (b != null &amp;&amp; c!=null)\r\n            {\r\n                int sum = a.data + b.data + c.data;\r\n                if (sum == givenNumber)\r\n                {\r\n                    System.out.println(&quot;Triplet found &quot; + a.data +&quot; &quot; + b.data + &quot; &quot; + c.data);\r\n                    return true;\r\n                }\r\n                \/\/ If sum is smaller then look for greater value of b\r\n                else if (sum &lt; givenNumber)\r\n                    b = b.next;\r\n                else\r\n                    c = c.next;\r\n            }\r\n            a = a.next;\r\n        }\r\n        System.out.println(&quot;No Triplet found&quot;);\r\n        return false;\r\n    }\r\n    void push(int new_data)\r\n    {\r\n        Node new_node = new Node(new_data);\r\n        new_node.next = head;\r\n        head = new_node;\r\n    }\r\n    public static void main(String args[])\r\n    {\r\n        Triplet llist1 = new Triplet();\r\n        Triplet llist2 = new Triplet();\r\n        Triplet llist3 = new Triplet();\r\n\r\n        \/* Create Linked List llist1 100-&gt;15-&gt;5-&gt;20 *\/\r\n        llist1.push(3);\r\n        llist1.push(8);\r\n        llist1.push(1);\r\n\r\n        \/*create a sorted linked list 'b' 2-&gt;4-&gt;9-&gt;10 *\/\r\n        llist2.push(2);\r\n        llist2.push(6);\r\n        llist2.push(8);\r\n\r\n        \/*create another sorted linked list 'c' 8-&gt;4-&gt;2-&gt;1 *\/\r\n        llist3.push(11);\r\n        llist3.push(4);\r\n        llist3.push(2);\r\n\r\n        int givenNumber = 14;\r\n        llist1.isSumSorted(llist1,llist2,llist3,givenNumber);\r\n    }\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_5842_4\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"Python\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"Python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nclass Node:\r\n    def __init__(self, new_data):\r\n        self.data = new_data\r\n        self.next = None\r\n\r\ndef push ( head_ref, new_data) :\r\n\r\n    new_node = Node(0)\r\n    new_node.data = new_data\r\n    new_node.next = (head_ref)\r\n    (head_ref) = new_node\r\n    return head_ref\r\n\r\ndef isSumSorted(headA, headB,headC, givenNumber) :\r\n\r\n    a = headA\r\n    while (a != None) :\r\n    \r\n        b = headB\r\n        c = headC\r\n\r\n        while (b != None and c != None) :\r\n        \r\n            sum = a.data + b.data + c.data\r\n            if (sum == givenNumber) :\r\n            \r\n                print(&quot;Triplet Found:&quot; , a.data , b.data , c.data)\r\n                return True\r\n            \r\n            elif (sum &lt; givenNumber):\r\n                b = b.next\r\n            else :\r\n                c = c.next\r\n        \r\n        a = a.next\r\n    \r\n    print(&quot;No such triplet&quot;)\r\n    return False\r\n\r\n\r\nheadA = None\r\nheadB = None\r\nheadC = None\r\n\r\nheadA = push (headA, 20)\r\nheadA = push (headA, 4)\r\nheadA = push (headA, 15)\r\nheadA = push (headA, 10)\r\n\r\nheadB = push (headB, 10)\r\nheadB = push (headB, 9)\r\nheadB = push (headB, 4)\r\nheadB = push (headB, 2)\r\n\r\nheadC = push (headC, 1)\r\nheadC = push (headC, 2)\r\nheadC = push (headC, 4)\r\nheadC = push (headC, 8)\r\n\r\ngivenNumber = 15\r\n\r\nisSumSorted (headA, headB, headC, givenNumber)\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_5842 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_5842 a\"),jQuery(\"#tab-content_5842\"));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<\/p>\n<p>    Output<br \/>\n    Triplet Found: 8 2 4<\/p>\n<p>**Time Complexity:** O(n<sup>2<\/sup>) ,n is the number of nodes in the list.<\/p>\n<p>This blog had deeply discussed how to find a triplet from three linked lists with a sum equal to a given number. Regularly practicing topics like linked list will increase your potential for getting a good job in tech companies like adobe, google, flipkart, samsung, amazon. For practicing more questions of linked list, our experts have prepared a list of linked list questions, you can check <a href=\"https:\/\/mycode.prepbytes.com\/interview-coding\/practice\/linked-list\">Linked List<\/a> for it.<\/p>\n<p>## FAQ<\/p>\n<p>**1. What are the 4 types of linked list?**<br \/>\nTypes of Linked List &#8211; Singly linked, doubly linked and circular<br \/>\n&#8211; Singly Linked List.<br \/>\n&#8211; Doubly Linked List.<br \/>\n&#8211; Circular Linked List.<\/p>\n<p>**2. How do you sum nodes in a linked list?**<br \/>\nSo to find the sum of all elements of the singly linked list, we have to navigate to each node of the linked list and add the element&#8217;s value to a sum variable. Suppose we have a linked list: 2 -> 27 -> 32 -> 1 -> 5 sum = 2 + 27 + 32 + 1 + 5 = 67.<\/p>\n<p>**3. How can you tell if two linked lists are identical?**<br \/>\nCheck if Linked-Lists are identical using linear traversal:<br \/>\nTraverse both the linked lists simultaneously. If the data of the current node for one linked list is not equal to the node of the other one, then return false.<br \/>\nReturn true, as both the linked lists are identical.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article will discuss in detail how to find a triplet from three linked lists with a sum equal to a given number. Linked list is a dominating topic when we look at the data structures and having a good grip on linked list will help in clearing the interviews for the tech interviews. Let\u2019s [&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-5841","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>Find a triplet from three linked lists with a sum equal to a given number | Linked List | Prepbytes<\/title>\n<meta name=\"description\" content=\"Learn how to find a triplet from three linked lists with a sum equal to a given number.\" \/>\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\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Find a triplet from three linked lists with a sum equal to a given number | Linked List | Prepbytes\" \/>\n<meta property=\"og:description\" content=\"Learn how to find a triplet from three linked lists with a sum equal to a given number.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/\" \/>\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-25T11:20:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-28T09:36:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012237824-Article_205.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\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Find a triplet from three linked lists with a sum equal to a given number\",\"datePublished\":\"2021-10-25T11:20:59+00:00\",\"dateModified\":\"2022-11-28T09:36:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/\"},\"wordCount\":1090,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012237824-Article_205.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/\",\"name\":\"Find a triplet from three linked lists with a sum equal to a given number | Linked List | Prepbytes\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012237824-Article_205.png\",\"datePublished\":\"2021-10-25T11:20:59+00:00\",\"dateModified\":\"2022-11-28T09:36:46+00:00\",\"description\":\"Learn how to find a triplet from three linked lists with a sum equal to a given number.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012237824-Article_205.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012237824-Article_205.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/#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\":\"Find a triplet from three linked lists with a sum equal to a given number\"}]},{\"@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":"Find a triplet from three linked lists with a sum equal to a given number | Linked List | Prepbytes","description":"Learn how to find a triplet from three linked lists with a sum equal to a given number.","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\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/","og_locale":"en_US","og_type":"article","og_title":"Find a triplet from three linked lists with a sum equal to a given number | Linked List | Prepbytes","og_description":"Learn how to find a triplet from three linked lists with a sum equal to a given number.","og_url":"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-10-25T11:20:59+00:00","article_modified_time":"2022-11-28T09:36:46+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012237824-Article_205.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\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Find a triplet from three linked lists with a sum equal to a given number","datePublished":"2021-10-25T11:20:59+00:00","dateModified":"2022-11-28T09:36:46+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/"},"wordCount":1090,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012237824-Article_205.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/","url":"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/","name":"Find a triplet from three linked lists with a sum equal to a given number | Linked List | Prepbytes","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012237824-Article_205.png","datePublished":"2021-10-25T11:20:59+00:00","dateModified":"2022-11-28T09:36:46+00:00","description":"Learn how to find a triplet from three linked lists with a sum equal to a given number.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012237824-Article_205.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645012237824-Article_205.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/find-a-triplet-from-three-linked-lists-with-a-sum-equal-to-a-given-number\/#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":"Find a triplet from three linked lists with a sum equal to a given number"}]},{"@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\/5841","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=5841"}],"version-history":[{"count":6,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5841\/revisions"}],"predecessor-version":[{"id":10786,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5841\/revisions\/10786"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=5841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=5841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=5841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}