{"id":5284,"date":"2021-09-27T19:45:22","date_gmt":"2021-09-27T19:45:22","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=5284"},"modified":"2022-11-28T10:42:07","modified_gmt":"2022-11-28T10:42:07","slug":"multiply-linked-lists","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/","title":{"rendered":"Multiply Linked Lists"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007849150-Article_170.png\" alt=\"\" \/><\/p>\n<p>In this article we will learn an interesting problem of a linked list \u201cmultiply two linked lists\u201d. We have given two linked lists and we have to perform the multiplication and return the head of the new list. <\/p>\n<h2>How to multiply two linked lists <\/h2>\n<p>We will be given two numbers in the form of a linked list, and we need to return a third list that will be the product of both the given lists.<\/p>\n<p>Let&#8217;s try to understand the problem with the help of an example:<\/p>\n<p>If the linked lists given to us be <strong>list1 = 2\u21923\u21925\u2192NULL<\/strong> and <strong>list2 = 1\u21924\u2192NULL<\/strong>.<\/p>\n<ul>\n<li>In numeric form, <strong>list1 = 2\u21923\u21925\u2192NULL<\/strong> can be represented as <strong>235<\/strong> and <strong>list2 = 1\u21924\u2192NULL<\/strong> can be represented as <strong>14<\/strong>.<\/li>\n<li>So, according to the problem statement, we need to multiply the given linked lists, i.e., find the product of the numeric form of list1 and list2, and return the product in the form of a linked list.<\/li>\n<li>The output list will be <strong>3\u21922\u21929\u21920\u2192NULL<\/strong>, because the product of the numeric form of list1 and list2 is *<em>235<\/em>14 = 3290**.<\/li>\n<\/ul>\n<p>Let\u2019s take another example. If the linked lists given to us be <strong>list1 = 6\u21927\u21924\u2192NULL<\/strong> and <strong>list2 = 2\u21929\u21925\u2192NULL<\/strong>.<\/p>\n<ul>\n<li>In this case, the numeric form of list1 will be <strong>674<\/strong>, and list2 will be <strong>295<\/strong>. So, our output will be the linked list representation of *<em>674<\/em>295 = 198830<strong>, which will be <\/strong>1\u21929\u21928\u21928\u21923\u21920\u2192NULL**.<\/li>\n<\/ul>\n<h5>Some more examples<\/h5>\n<p>Sample Input 1: <\/p>\n<ul>\n<li>list1: 1\u21923\u21925\u2192NULL<\/li>\n<li>list2: 2\u21923\u21924\u2192NULL<\/li>\n<\/ul>\n<p>Sample Output 1: 3\u21921\u21925\u21929\u21920\u2192NULL<\/p>\n<p>Sample Output 2:<\/p>\n<ul>\n<li>list1: 1\u21926\u21924\u21928\u2192NULL<\/li>\n<li>list2:  1\u21922\u21923\u21924\u2192NULL<\/li>\n<\/ul>\n<p>Sample Output 2: 2\u21920\u21923\u21923\u21926\u21923\u21922\u2192NULL<\/p>\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 of multiply two linked lists <\/h2>\n<ul>\n<li>The input list given to us will contain the most significant digit as the head and the least significant as the last node.<\/li>\n<li>We know that, for multiplication, we need to start multiplying the digit from the least significant digit to the most significant one.<\/li>\n<li>We cannot traverse backward in the list so, first, we need to reverse both the lists.<\/li>\n<li>Now, we will multiply each digit of the second list one by one with a complete first list (just as we do a normal multiplication on pen-paper).<\/li>\n<li>We will multiply the first digit of the second list with the complete first list and save it to use afterwards.<\/li>\n<li>Then, we will multiply the second digit of the second list with the complete first list and add this list with the previously obtained list by shifting the elements of this list by one place to the right. <\/li>\n<li>We will repeat the above steps of multiplication of digits of second list with the complete first list until we reach the second list&#8217;s end.<\/li>\n<li>Remember to take care of carry while doing addition and multiplication.<\/li>\n<li>Finally, we will reverse the obtained list and return it.<\/li>\n<\/ul>\n<h2>Algorithm of multiply two linked lists <\/h2>\n<ul>\n<li>Reverse both the linked lists.<\/li>\n<li>Create a <strong>dummy node<\/strong> with a value of -1 and name it as <strong>ans<\/strong>. Also, initialize a pointer <strong>ans_itr<\/strong> with the address of the dummy node and a pointer <strong>l2_itr<\/strong> with the head of the second list.<\/li>\n<li>Now, run a while loop till <strong>l2_itr<\/strong> is not NULL.<\/li>\n<li>Create a <strong>head<\/strong> pointer that will call <strong>multiplyLinkedListWithDigit<\/strong> function with <strong>l1<\/strong> and <strong>l2_itr-&gt;data<\/strong> as parameters. (This function will multiply the single digit of the second list\u2019s node with the complete first list).<\/li>\n<li>Now, control moves to <strong>multiplyLinkedListWithDigit function<\/strong>:\n<ul>\n<li>Create a <strong>dummy node<\/strong> with a value of -1 and name it <strong>head<\/strong>. Also, initialize a pointer named <strong>curr<\/strong> with it and an integer variable <strong>carry<\/strong> with zero.<\/li>\n<li>Run a while loop till <strong>l1<\/strong> is not NULL or carry is non-zero.<\/li>\n<li>Calculate the <strong>sum<\/strong> variable as the sum of <strong>carry<\/strong> and If <strong>l1<\/strong> is not NULL, then the product of <strong>digit<\/strong> and <strong>l1-&gt;data<\/strong>.<\/li>\n<li>Now, update <strong>carry<\/strong> by removing the last digit from the <strong>sum<\/strong> by doing <strong>sum\/10<\/strong>.<\/li>\n<li>Update <strong>sum<\/strong> as the last digit of sum, i.e., <strong>sum %= 10<\/strong>.<\/li>\n<li>Create a new node with the value of sum and attach it after the <strong>curr<\/strong> node.<\/li>\n<li>If  <strong>l1<\/strong> is not NULL, advance <strong>l1<\/strong> by a node <\/li>\n<li>Advance <strong>curr<\/strong> pointer by one node.<\/li>\n<li>After execution of the while loop, return <strong>head-&gt;next<\/strong> as the head was the dummy node created initially.<\/li>\n<\/ul>\n<\/li>\n<li>Now, advance the <strong>l2_itr<\/strong> to the next node for further multiplication.<\/li>\n<li>Update the <strong>ans_itr<\/strong> function by calling the <strong>addTwoLinkedList function<\/strong> with <strong>ans_itr<\/strong> and <strong>head<\/strong> as parameters.<\/li>\n<li>Now the control moves to <strong>addTwoLinkedList function<\/strong>:\n<ul>\n<li>Initialize a <strong>prev<\/strong> pointer with the head of the first list and an integer variable <strong>carry<\/strong> with zero.<\/li>\n<li>Run a while loop till <strong>l2<\/strong> is not NULL or <strong>carry<\/strong> is non-zero.<\/li>\n<li>Calculate <strong>sum<\/strong> by adding <strong>carry<\/strong>, <strong>prev-&gt;next-&gt;data<\/strong> if <strong>prev-&gt;next<\/strong> is not NULL and <strong>l2-&gt;data<\/strong> if l2 is not NULL.<\/li>\n<li>Now, update <strong>carry<\/strong> by removing the last digit from the <strong>sum<\/strong> by doing <strong>sum\/10<\/strong>.<\/li>\n<li>Update <strong>sum<\/strong> as the last digit of <strong>sum<\/strong> i.e., <strong>sum %= 10<\/strong>.<\/li>\n<li>Check if <strong>prev-&gt;next<\/strong> is NULL or not.<\/li>\n<li>If it is not NULL then, assign <strong>sum<\/strong> value to <strong>prev-&gt;next-&gt;data<\/strong>.<\/li>\n<li>Else, create a new node with <strong>sum<\/strong> value and attach it after <strong>prev<\/strong>.<\/li>\n<li>If <strong>l2<\/strong> is not NULL, advance <strong>l2<\/strong> by one node.<\/li>\n<li>Advance <strong>prev<\/strong> by one node.<\/li>\n<li>After execution of the loop, return <strong>l1<\/strong>.<\/li>\n<\/ul>\n<\/li>\n<li>Advance <strong>ans_itr<\/strong> by one node.<\/li>\n<li>After completion of the while loop, advance <strong>ans<\/strong> by one node, as <strong>ans<\/strong> was a dummy node created initially.<\/li>\n<li>Now, reverse the list having <strong>ans<\/strong> as head and return it.<\/li>\n<\/ul>\n<p><strong>Note:<\/strong> To understand the algorithm better, follow along with code.<\/p>\n<h3>Dry Run of multiply two linked lists <\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_1-26.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_2-26.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_3-15.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_4-10.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_5_p_6.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_7_p_8.png\" alt=\"\" \/><\/p>\n<p>## Code Implementation of multiply two linked lists<\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_5285 {\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_5285 .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_5285 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_5285 .wpsm_nav-tabs > li.active > a, #tab_container_5285 .wpsm_nav-tabs > li.active > a:hover, #tab_container_5285 .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_5285 .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_5285 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_5285 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_5285 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_5285 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_5285 .wpsm_nav-tabs > li > a:hover , #tab_container_5285 .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_5285 .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_5285 .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_5285 .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_5285 .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_5285 .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_5285 .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_5285 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5285 .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_5285 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5285 .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_5285 .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_5285\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_5285\">\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_5285_1\" aria-controls=\"tabs_desc_5285_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_5285_2\" aria-controls=\"tabs_desc_5285_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_5285_3\" aria-controls=\"tabs_desc_5285_3\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Java<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_5285\">\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_5285_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"c\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n \r\n\/* Link list node *\/\r\nstruct Node {\r\n    int data;\r\n    struct Node* next;\r\n};\r\n \r\nint getCount(struct Node* head);\r\n \r\nint _getIntesectionNode(int d, struct Node* head1, struct Node* head2);\r\n \r\nint getIntesectionNode(struct Node* head1, struct Node* head2)\r\n{\r\n    int c1 = getCount(head1);\r\n    int c2 = getCount(head2);\r\n    int d;\r\n \r\n    if (c1 &gt; c2) {\r\n        d = c1 - c2;\r\n        return _getIntesectionNode(d, head1, head2);\r\n    }\r\n    else {\r\n        d = c2 - c1;\r\n        return _getIntesectionNode(d, head2, head1);\r\n    }\r\n}\r\n \r\nint _getIntesectionNode(int d, struct Node* head1, struct Node* head2)\r\n{\r\n    int i;\r\n    struct Node* current1 = head1;\r\n    struct Node* current2 = head2;\r\n \r\n    for (i = 0; i &lt; d; i++) {\r\n        if (current1 == NULL) {\r\n            return -1;\r\n        }\r\n        current1 = current1-&gt;next;\r\n    }\r\n \r\n    while (current1 != NULL &amp;&amp; current2 != NULL) {\r\n        if (current1 == current2)\r\n            return current1-&gt;data;\r\n        current1 = current1-&gt;next;\r\n        current2 = current2-&gt;next;\r\n    }\r\n \r\n    return -1;\r\n}\r\n \r\nint getCount(struct Node* head)\r\n{\r\n    struct Node* current = head;\r\n    int count = 0;\r\n \r\n    while (current != NULL) {\r\n        count++;\r\n        current = current-&gt;next;\r\n    }\r\n \r\n    return count;\r\n}\r\n \r\nint main()\r\n{\r\n    \r\n \r\n    struct Node* newNode;\r\n    struct Node* head1 = (struct Node*)malloc(sizeof(struct Node));\r\n    head1-&gt;data = 10;\r\n \r\n    struct Node* head2 = (struct Node*)malloc(sizeof(struct Node));\r\n    head2-&gt;data = 3;\r\n \r\n    newNode = (struct Node*)malloc(sizeof(struct Node));\r\n    newNode-&gt;data = 6;\r\n    head2-&gt;next = newNode;\r\n \r\n    newNode = (struct Node*)malloc(sizeof(struct Node));\r\n    newNode-&gt;data = 9;\r\n    head2-&gt;next-&gt;next = newNode;\r\n \r\n    newNode = (struct Node*)malloc(sizeof(struct Node));\r\n    newNode-&gt;data = 15;\r\n    head1-&gt;next = newNode;\r\n    head2-&gt;next-&gt;next-&gt;next = newNode;\r\n \r\n    newNode = (struct Node*)malloc(sizeof(struct Node));\r\n    newNode-&gt;data = 30;\r\n    head1-&gt;next-&gt;next = newNode;\r\n \r\n    head1-&gt;next-&gt;next-&gt;next = NULL;\r\n \r\n    printf(&quot;&#92;n The node of intersection is %d &#92;n&quot;,\r\n           getIntesectionNode(head1, head2));\r\n \r\n    getchar();\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_5285_2\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"cpp\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include&lt;bits\/stdc++.h&gt;\r\nusing namespace std;\r\nclass Node {\r\n    public:\r\n    int data;\r\n    Node* next;\r\n    \/\/ constructor\r\n    Node(int x){\r\n        data = x;\r\n        next = NULL;\r\n    }\r\n};\r\n\/\/ This function prints the data of a given list \r\nvoid print(Node* head)\r\n{\r\n    Node* curr = head;\r\n    while (curr != NULL) {\r\n        cout &lt;&lt; curr-&gt;data &lt;&lt; &quot; -&gt; &quot;;\r\n        curr = curr-&gt;next;\r\n    }\r\n    cout&lt;&lt;&quot;NULL&quot;;\r\n}\r\n\/\/ This function will reverse a given list\r\nNode* reverse(Node *head)\r\n{\r\n    Node *prev = NULL, *current = head, *next;\r\n    while (current != NULL)\r\n    {\r\n        next  = current-&gt;next;\r\n        current-&gt;next = prev;\r\n        prev = current;\r\n        current = next;\r\n    }\r\n    return prev;\r\n}\r\n\/\/ This function will add two lists and it also shifts the\r\n\/\/ second list by one place while adding and then returns the\r\n\/\/ result in a third list\r\nNode* addTwoLinkedList(Node *l1, Node *l2) {\r\n    Node *prev = l1;\r\n    int carry = 0;\r\n    while (l2 != NULL || carry != 0) {\r\n        int sum = carry \r\n+ (prev-&gt;next != NULL ? prev-&gt;next-&gt;data : 0) \r\n+ (l2 != NULL ? l2-&gt;data : 0);\r\n\r\n        carry = sum \/ 10;\r\n        sum = sum % 10;\r\n\r\n        if (prev-&gt;next != NULL)\r\n            prev-&gt;next-&gt;data = sum;\r\n        else\r\n            prev-&gt;next = new Node(sum);\r\n\r\n        if (l2 != NULL)\r\n            l2 = l2-&gt;next;\r\n        prev = prev-&gt;next;\r\n    }\r\n    return l1;\r\n}\r\n\r\n\/\/ This function multiplies a linked list with an integer and\r\n\/\/ returns the result of multiplication as a list\r\nNode* multiplyLinkedListWithDigit(Node* l1, int digit) {\r\n    Node* head = new Node(-1); \/\/ dummy node\r\n    Node* curr = head;\r\n\r\n    int carry = 0;\r\n    while (l1 != NULL || carry != 0) {\r\n        int sum = carry + (l1 != NULL ? (l1-&gt;data * digit) : 0);\r\n\r\n        carry = sum \/ 10;\r\n        sum = sum % 10;\r\n\r\n        curr-&gt;next = new Node(sum);\r\n\r\n        if (l1 != NULL)\r\n            l1 = l1-&gt;next;\r\n        curr = curr-&gt;next;\r\n    }\r\n\r\n    return head-&gt;next;\r\n}\r\n\/\/ This function will multiply two linked lists and return\r\n\/\/ a third list which will be having the result of \r\n\/\/ multiplication\r\nNode* multiplyTwoLL(Node* l1, Node* l2) {\r\n    l1 = reverse(l1);\r\n    l2 = reverse(l2);\r\n\r\n    Node* ans = new Node(-1); \/\/ dummy node\r\n    Node* ans_itr = ans;\r\n    Node* l2_itr = l2;\r\n\r\n    while (l2_itr != NULL) {\r\n        Node* head = multiplyLinkedListWithDigit(l1, l2_itr-&gt;data);\r\n        l2_itr = l2_itr-&gt;next;\r\n        ans_itr = addTwoLinkedList(ans_itr,head);\r\n        ans_itr = ans_itr-&gt;next;\r\n    }\r\n    \r\n    ans = ans-&gt;next;\r\n    return reverse(ans);\r\n}\r\n\r\nint main(){\r\n    Node *list1 = new Node(2);\r\n    list1-&gt;next = new Node(3);\r\n    list1-&gt;next-&gt;next = new Node(5);\r\n\r\n    Node *list2 = new Node(1);\r\n    list2-&gt;next = new Node(4);\r\n\r\n    cout&lt;&lt;&quot;Linked list obtained by multiplying list1 and list2: &quot;&lt;&lt;endl;\r\n    print(multiplyTwoLL(list1,list2));\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_5285_3\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"java\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nclass Node \r\n{\r\n\tint data;\r\n\tNode next;\r\n\tNode(int data)\r\n\t{\r\n\t\tthis.data=data;\r\n\t}\r\n}\r\nclass Multiply \r\n{\r\n\tstatic void print(Node head)\r\n\t{\r\n\t\tNode curr=head;\r\n\t\twhile(curr!=null)\r\n\t\t{\r\n\t\t\tSystem.out.print(curr.data+\"->\");\r\n\t\t\tcurr=curr.next;\r\n\t\t}\r\n\t\tSystem.out.println(\"NULL\");\r\n\t}\r\n\tstatic Node reverse(Node head)\r\n\t{\r\n\t\tNode prev=null,current=head,next;\r\n\t\twhile(current!=null)\r\n\t\t{\r\n\t\t\tnext=current.next;\r\n\t\t\tcurrent.next=prev;\r\n\t\t\tprev=current;\r\n\t\t\tcurrent=next;\r\n\t\t}\r\n\t\treturn prev;\r\n\t}\r\n\tstatic Node addTwoLinkedList(Node l1,Node l2)\r\n\t{\r\n\t\tNode prev=l1;\r\n\t\tint carry=0;\r\n\t\twhile(l2!=null || carry!=0)\r\n\t\t{\r\n\t\t\tint sum=carry+(prev.next!=null ? prev.next.data : 0)+ (l2!=null ? l2.data : 0);\r\n\t\t\tcarry=sum\/10;\r\n\t\t\tsum=sum%10;\r\n\r\n\t\t\tif(prev.next!=null)\r\n\t\t\t{\r\n\t\t\t\tprev.next.data=sum;\r\n\t\t\t}\r\n\t\t\telse \r\n\t\t\t{\r\n\t\t\t\tprev.next=new Node(sum);\r\n\t\t\t}\r\n\t\t\tif(l2!=null)\r\n\t\t\t{\r\n\t\t\t\tl2=l2.next;\r\n\t\t\t}\r\n\t\t\tprev=prev.next;\r\n\t\t}\r\n\t\treturn l1;\r\n\t}\r\n\tstatic Node multiplyLinkedListWithDigit(Node l1,int digit)\r\n\t{\r\n\t\tNode head=new Node(-1);\r\n\t\tNode curr=head;\r\n\r\n\t\tint carry=0;\r\n\t\twhile(l1!=null || carry!=0)\r\n\t\t{\r\n\t\t\tint sum=carry+(l1!=null ? (l1.data*digit) : 0);\r\n\t\t\tcarry=sum\/10;\r\n\t\t\tsum=sum%10;\r\n\r\n\t\t\tcurr.next=new Node(sum);\r\n\t\t\tif(l1!=null)\r\n\t\t\t{\r\n\t\t\t\tl1=l1.next;\r\n\t\t\t}\r\n\t\t\tcurr=curr.next;\r\n\t\t}\r\n\t\treturn head.next;\r\n\t}\r\n\tstatic Node multiplyTwoLL(Node l1,Node l2)\r\n\t{\r\n\t\tl1=reverse(l1);\r\n\t\tl2=reverse(l2);\r\n\r\n\t\tNode ans=new Node(-1);\r\n\t\tNode ans_itr=ans;\r\n\t\tNode l2_itr=l2;\r\n\r\n\t\twhile(l2_itr!=null)\r\n\t\t{\r\n\t\t\tNode head=multiplyLinkedListWithDigit(l1, l2_itr.data);\r\n\t\t\tl2_itr=l2_itr.next;\r\n\t\t\tans_itr=addTwoLinkedList(ans_itr,head);\r\n\t\t\tans_itr=ans_itr.next;\r\n\t\t}\r\n\t\tans=ans.next;\r\n\t\treturn reverse(ans);\r\n\t}\r\n\tpublic static void main(String[] args) \r\n\t{\r\n\t\tNode list1=new Node(2);\r\n\t\tlist1.next=new Node(3);\r\n\t\tlist1.next.next=new Node(5);\r\n\t\t\r\n\t\tNode list2=new Node(1);\r\n\t\tlist2.next=new Node(4);\r\n\r\n\t\tSystem.out.println(\"LinkedList obtained by multiplying list 1 and list 2 :\");\r\n\t\tprint(multiplyTwoLL(list1, list2));\r\n\t}\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_5285 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_5285 a\"),jQuery(\"#tab-content_5285\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p>    Output<br \/>\n    Linked list obtained by multiplying list1 and list2:<br \/>\n    3 -> 2 -> 9 -> 0 -> NULL<\/p>\n<p><strong>Time Complexity of multiply two linked lists :<\/strong> O(N*M), where N and M are the numbers of nodes in the linked list 1 and 2.<br \/>\n<strong>Space Complexity of multiply two linked lists :<\/strong> O(X), where X will be the number of nodes in the resultant list.<\/p>\n<p>**Conclusion**<\/p>\n<p>So, in this blog, we have tried to explain how you can multiply two linked lists in the most optimal way. This is one of the good problems that help you strengthen your concepts in LinkedList and if you want to practice more such problems, you can check out <a href=\"https:\/\/mycode.prepbytes.com\/interview-coding\/practice\/linked-list\">Prepbytes (Linked List)<\/a>.<\/p>\n<p>## FAQs related to multiply two linked lists<\/p>\n<p>**1. How do you multiply two linked lists?**<br \/>\nWe will multiply two linked lists:<br \/>\n&#8211; Initialize a variable to 0.<br \/>\n&#8211; Start traversing the linked list.<br \/>\n&#8211; Assign the value of the first node to the new variable.<br \/>\n&#8211; From the second node, multiply the variable by 10 and also take the modulus of this value by 10^9+7 and then add the value of the node to this variable.<\/p>\n<p>**2. What is the multiple-linked list?**<br \/>\nMultilevel Linked List is a 2D data structure that comprises several linked lists and each node in a multilevel linked list has a next and child pointer. All the elements are linked using pointers.<\/p>\n<p>**3. What is a doubly linked list?**<br \/>\nA doubly linked list is a complex type of linked list in which a node contains a pointer to the previous as well as the next node in the sequence.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article we will learn an interesting problem of a linked list \u201cmultiply two linked lists\u201d. We have given two linked lists and we have to perform the multiplication and return the head of the new list. How to multiply two linked lists We will be given two numbers in the form of a [&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-5284","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>Multiply Linked Lists | Linked list articles | PrepBytes Blog<\/title>\n<meta name=\"description\" content=\"Learn how to multiply two linked lists and return the result in form of a third list.\" \/>\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\/multiply-linked-lists\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Multiply Linked Lists | Linked list articles | PrepBytes Blog\" \/>\n<meta property=\"og:description\" content=\"Learn how to multiply two linked lists and return the result in form of a third list.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/multiply-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-09-27T19:45:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-28T10:42:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007849150-Article_170.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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Multiply Linked Lists\",\"datePublished\":\"2021-09-27T19:45:22+00:00\",\"dateModified\":\"2022-11-28T10:42:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/\"},\"wordCount\":1249,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007849150-Article_170.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/\",\"name\":\"Multiply Linked Lists | Linked list articles | PrepBytes Blog\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007849150-Article_170.png\",\"datePublished\":\"2021-09-27T19:45:22+00:00\",\"dateModified\":\"2022-11-28T10:42:07+00:00\",\"description\":\"Learn how to multiply two linked lists and return the result in form of a third list.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007849150-Article_170.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007849150-Article_170.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-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\":\"Multiply 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":"Multiply Linked Lists | Linked list articles | PrepBytes Blog","description":"Learn how to multiply two linked lists and return the result in form of a third list.","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\/multiply-linked-lists\/","og_locale":"en_US","og_type":"article","og_title":"Multiply Linked Lists | Linked list articles | PrepBytes Blog","og_description":"Learn how to multiply two linked lists and return the result in form of a third list.","og_url":"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-09-27T19:45:22+00:00","article_modified_time":"2022-11-28T10:42:07+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007849150-Article_170.png","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Multiply Linked Lists","datePublished":"2021-09-27T19:45:22+00:00","dateModified":"2022-11-28T10:42:07+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/"},"wordCount":1249,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007849150-Article_170.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/","url":"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/","name":"Multiply Linked Lists | Linked list articles | PrepBytes Blog","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007849150-Article_170.png","datePublished":"2021-09-27T19:45:22+00:00","dateModified":"2022-11-28T10:42:07+00:00","description":"Learn how to multiply two linked lists and return the result in form of a third list.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/multiply-linked-lists\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007849150-Article_170.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007849150-Article_170.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/multiply-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":"Multiply 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\/5284","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=5284"}],"version-history":[{"count":7,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5284\/revisions"}],"predecessor-version":[{"id":10792,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5284\/revisions\/10792"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=5284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=5284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=5284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}