{"id":4331,"date":"2021-08-25T09:40:32","date_gmt":"2021-08-25T09:40:32","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=4331"},"modified":"2023-07-24T05:31:42","modified_gmt":"2023-07-24T05:31:42","slug":"multiply-two-numbers-represented-by-linked-lists","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/","title":{"rendered":"Multiply two numbers represented by Linked Lists"},"content":{"rendered":"<p>This article aims to demonstrate how to multiply two numbers represented by linked lists. In this problem, we are given two linked lists, L1 and L2. Both L1 and L2 are numbers represented as linked lists. We are required to multiply these Lists and produce the output. Let\u2019s take a look at how to multiply two linked lists<\/p>\n<h2>How to Multiply two numbers represented by Linked Lists<\/h2>\n<p>Let\u2019s try to understand the problem with help of examples by referring the best online learning sites for programming.<\/p>\n<p>Suppose the given linked lists are:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-1-l1.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-1-l2.png\" alt=\"\" \/><\/p>\n<p>Now, according to the problem statement, these linked lists <strong>L1<\/strong> and <strong>L2<\/strong> are actually two numbers which are represented using linked lists.<br \/>\nFor example, we can represent<\/p>\n<ul>\n<li>The number 23 as 2\u21923 using linked list.<\/li>\n<li>The number 234 as 2\u21923\u21924 using linked list.<\/li>\n<li>More generically speaking, we can represent a number abcd as a\u2192b\u2192c\u2192d using linked list.<\/li>\n<\/ul>\n<p>And our output is the multiplication of these two numbers <strong>L1<\/strong> and <strong>L2<\/strong>, represented as a linked list.<\/p>\n<ul>\n<li>As <strong>L1<\/strong> = 5\u21926\u21921, so the number is 561.<\/li>\n<li>And as <strong>L2<\/strong> = 4\u21922, the number is 42.<\/li>\n<\/ul>\n<p><strong>Output<\/strong> = 561*42 = 23562<\/p>\n<p>Let\u2019s say if:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-2-l1.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-2-l2.png\" alt=\"\" \/><\/p>\n<ul>\n<li>Corresponding numbers for <strong>L1<\/strong> and <strong>L2<\/strong> will be 2345 and 345.<\/li>\n<\/ul>\n<p><strong>Output<\/strong> = 2345*345 = 809025<\/p>\n<h4>Some more examples:<\/h4>\n<p><strong>Input:<\/strong> L1 = 3\u21922\u21921, L2 = 2\u21921<br \/>\n<strong>Output:<\/strong> 6741<\/p>\n<p><strong>Input:<\/strong> L1 = 3\u21922, L2 = 1\u21927<br \/>\n<strong>Output:<\/strong> 544<\/p>\n<p><strong>Input:<\/strong> L1 = 9\u21928\u21927, L2 = 1\u21922\u21923<br \/>\n<strong>Output:<\/strong> 121401<\/p>\n<p>Now, I hope that from the above examples, you got an idea about what the problem is. So now let\u2019s move towards finding some approach to solve this problem.<\/p>\n<h3>Approach to multiply two numbers represented by linked lists.<\/h3>\n<p>Firstly, traverse through both lists and produce the numbers required to be multiplied, and then return the multiplied values of the two numbers. <\/p>\n<h5>Algorithm to multiply two numbers represented by linked lists<\/h5>\n<ul>\n<li>Initialize a variable num to zero.<\/li>\n<li>Begin traversing through the linked list.<\/li>\n<li>Add the data of the first node to this variable num.<\/li>\n<li>Second node onwards,<br \/>\n1) multiply the variable num by 10<br \/>\n2) and take the modulus of this value by 10<sup>9<\/sup>+7  as well,<br \/>\n3) and then add the data of the node to the variable num.<\/li>\n<li>Repeat the previous step until we arrive at the last node of the list. <\/li>\n<\/ul>\n<p>First, using the above-discussed algorithm for producing the number from linked list representation, we will produce the required numbers from the given linked lists <strong>L1<\/strong> and <strong>L2<\/strong>.<\/p>\n<p>After the numbers have been produced, we will multiply them to get the output.<\/p>\n<h3>Dry Run of multiply two numbers represented by linked lists<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Multiply-two-numbers-represented-by-Linked-list-1.png\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Multiply-two-numbers-represented-by-Linked-list-2.png\" alt=\"\" \/><\/p>\n<h3>Code Implementation of how to multiply two numbers represented by linked lists<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_4332 {\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_4332 .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_4332 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_4332 .wpsm_nav-tabs > li.active > a, #tab_container_4332 .wpsm_nav-tabs > li.active > a:hover, #tab_container_4332 .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_4332 .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_4332 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_4332 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_4332 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_4332 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_4332 .wpsm_nav-tabs > li > a:hover , #tab_container_4332 .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_4332 .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_4332 .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_4332 .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_4332 .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_4332 .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_4332 .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_4332 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_4332 .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_4332 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_4332 .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_4332 .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_4332\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_4332\">\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_4332_1\" aria-controls=\"tabs_desc_4332_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_4332_2\" aria-controls=\"tabs_desc_4332_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_4332_3\" aria-controls=\"tabs_desc_4332_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_4332_4\" aria-controls=\"tabs_desc_4332_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_4332\">\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_4332_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"c\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include<stdio.h>\r\n#include<stdlib.h>\r\n\r\nstruct Node\r\n{\r\n    int data;\r\n    struct Node* next;\r\n};\r\n   \r\n\/\/ Function to create a new node\r\n\/\/ with given data\r\nstruct Node *newNode(int data)\r\n{\r\n    struct Node *new_node = (struct Node *) malloc(sizeof(struct Node));\r\n    new_node->data = data;\r\n    new_node->next = NULL;\r\n    return new_node;\r\n}\r\n   \r\n\/\/ Function to insert a node at the\r\n\/\/ beginning of the Linked List\r\nvoid push(struct Node** head_ref, int new_data)\r\n{\r\n    \/\/ allocate node\r\n    struct Node* new_node = newNode(new_data);\r\n   \r\n    \/\/ link the old list off the new node\r\n    new_node->next = (*head_ref);\r\n   \r\n    \/\/ move the head to point to the new node\r\n    (*head_ref) = new_node;\r\n}\r\n   \r\n\/\/ Multiply contents of two linked lists\r\nlong long multiplyTwoLists (struct Node* first,struct Node* second)\r\n{\r\n    long long N= 1000000007;\r\n    long long num1 = 0, num2 = 0;\r\n    while (first || second){\r\n         \r\n        if(first){\r\n            num1 = ((num1)*10)%N + first->data;\r\n            first = first->next;\r\n        }\r\n         \r\n        if(second)\r\n        {\r\n            num2 = ((num2)*10)%N + second->data;\r\n            second = second->next;\r\n        }\r\n         \r\n    }\r\n    return ((num1%N)*(num2%N))%N;\r\n}\r\n   \r\n\/\/ A utility function to print a linked list\r\nvoid printList(struct Node *node)\r\n{\r\n    while(node != NULL)\r\n    {\r\n        printf(\"%d\",node->data);\r\n        if(node->next)\r\n            printf(\"->\");\r\n        node = node->next;\r\n    }\r\n    printf(\"&#92;n\");\r\n}\r\n   \r\n\/\/ Driver program to test above function\r\nint main()\r\n{\r\n    struct Node* first = NULL;\r\n    struct Node* second = NULL;\r\n   \r\n    \/\/ create first list 9->4->6\r\n    push(&first, 6);\r\n    push(&first, 4);\r\n    push(&first, 9);\r\n    printf(\"First List is: \");\r\n    printList(first);\r\n   \r\n    \/\/ create second list 8->4\r\n    push(&second, 4);\r\n    push(&second, 8);\r\n    printf(\"Second List is: \");\r\n    printList(second);\r\n   \r\n    \/\/ Multiply the two lists and see result\r\n    printf(\"Result is: \");\r\n    long long ans = multiplyTwoLists(first, second);\r\n    printf(\"%lld\",ans);\r\n   \r\n    return 0;\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_4332_2\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"cpp\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include<bits\/stdc++.h>\r\n#include<stdio.h>\r\nusing namespace std;\r\n\r\n\/\/ Linked list node\r\nstruct Node\r\n{\r\n    int val;\r\n    struct Node* next;\r\n};\r\n\r\n\/\/ Function for creating a new node with given value\r\nstruct Node *create_node(int val)\r\n{\r\n    struct Node *node_new = (struct Node *)\r\nmalloc(sizeof(struct Node));\r\n\r\n\/\/ putting the data into the new node.\r\n    node_new->val = val;\r\n    \/\/ initially new node points to NULL\r\n    node_new->next = NULL;\r\n\r\n    return node_new;\r\n}\r\n\r\n\/\/ Function for inserting a node\r\n\/\/ at the start of the Linked List\r\nvoid push(struct Node** head_ref, int new_val)\r\n{\r\n    \/\/ assigning the node\r\n    struct Node* node_new = create_node(new_val);\r\n\r\n    \/\/ Now, link old list off the new node\r\n    node_new->next = (*head_ref);\r\n\r\n    \/\/ moving the head inorder to point to the new node\r\n    (*head_ref) = node_new;\r\n}\r\n\r\n\/\/ to multiply data present in the two linked lists\r\nlong long multiplication (Node* list_one, Node* list_two)\r\n{\r\n    long long n= 1000000007;\r\n    long long first_num = 0, second_num = 0;\r\n    while (list_one || list_two){\r\n        \r\n        if(list_one){\r\n            first_num = ((first_num)*10)%n + list_one->val;\r\n            list_one = list_one->next;\r\n        }\r\n        \r\n        if(list_two)\r\n        {\r\n            second_num = ((second_num)*10)%n + list_two->val;\r\n            list_two = list_two->next;\r\n        }\r\n        \r\n    }\r\n    return ((first_num%n)*(second_num%n))%n;\r\n}\r\n\r\n\/\/ For printing the linked list\r\nvoid display_list(struct Node *node)\r\n{\r\n    while(node != NULL)\r\n    {\r\n        cout<<node->val;\r\n        if(node->next)\r\n            cout<<\"->\";\r\n        node = node->next;\r\n    }\r\n}\r\n\r\n\/\/ Driver function\r\nint main()\r\n{\r\n    struct Node* one = NULL;\r\n    struct Node* two = NULL;\r\n\r\n    \/\/ creating list one 5->6->1\r\n    push(&one, 1);\r\n    push(&one, 6);\r\n    push(&one, 5);\r\n    printf(\"List one is: \");\r\n    display_list(one);\r\n    \r\n    cout<<\u201d&#92;n\u201d;\r\n\r\n    \/\/ creating list two 4->2\r\n    push(&two, 2);\r\n    push(&two, 4);\r\n    printf(\"List two is: \");\r\n    display_list(two);\r\n    \r\n    cout<<\u201d&#92;n\u201d;\r\n\r\n    \/\/ Results after multiplying the two numbers.\r\n    cout<<\u201dAnswer: \u201c<<multiplication(one, two);\r\n\r\n    return 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_4332_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 Multiply\r\n{\r\n    static class Node\r\n    {\r\n        int data;\r\n        Node next;\r\n        \r\n        Node(int data){\r\n            this.data = data;\r\n            next = null;\r\n        }\r\n    }\r\n    \/\/ Multiply contents of two linked lists\r\n    static long multiplyTwoLists(Node first, Node second)\r\n    {\r\n        long N = 1000000007;\r\n        long num1 = 0, num2 = 0;\r\n\r\n        while (first != null || second != null){\r\n            \r\n            if(first != null){\r\n                num1 = ((num1)*10)%N + first.data;\r\n                first = first.next;\r\n            }\r\n            \r\n            if(second != null)\r\n            {\r\n                num2 = ((num2)*10)%N + second.data;\r\n                second = second.next;\r\n            }\r\n            \r\n        }\r\n        return ((num1%N)*(num2%N))%N;\r\n    }\r\n    static void printList(Node node)\r\n    {\r\n        while(node != null)\r\n        {\r\n            System.out.print(node.data);\r\n            if(node.next != null)\r\n                System.out.print(\"->\");\r\n            node = node.next;\r\n        }\r\n        System.out.println();\r\n    }\r\n\r\n    \/\/ Driver program to test above function\r\n    public static void main(String args[])\r\n    {\r\n        \/\/ create first list 9->4->6\r\n        Node first = new Node(9);\r\n        first.next = new Node(4);\r\n        first.next.next = new Node(6);\r\n        System.out.print(\"First List is: \");\r\n        printList(first);\r\n\r\n        \/\/ create second list 8->4\r\n        Node second = new Node(8);\r\n        second.next = new Node(4);\r\n        System.out.print(\"Second List is: \");\r\n        printList(second);\r\n\r\n        \/\/ Multiply the two lists and see result\r\n        System.out.print(\"Result is: \");\r\n        System.out.println(multiplyTwoLists(first, second));\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_4332_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\n\r\nclass Node:\r\n    \r\n    def __init__(self, data):\r\n        \r\n        self.data = data\r\n        self.next = None\r\n    \r\nclass LinkedList:\r\n\r\n    def __init__(self):\r\n\r\n        self.head = None\r\n\r\n    # Function to insert a node at the\r\n    # beginning of the Linked List\r\n    def push(self, new_data):\r\n    \r\n        # Create a new Node\r\n        new_node = Node(new_data)\r\n\r\n        # Make next of the new Node as head\r\n        new_node.next = self.head\r\n\r\n        # Move the head to point to new Node\r\n        self.head = new_node\r\n        \r\n    # Function to print the Linked List\r\n    def printList(self):\r\n        \r\n        ptr = self.head\r\n\r\n        while (ptr != None):\r\n            print(ptr.data, end = '')\r\n            if ptr.next != None:\r\n                print('->', end = '')\r\n                \r\n            ptr = ptr.next\r\n            \r\n        print()\r\n\r\n# Multiply contents of two Linked Lists\r\ndef multiplyTwoLists(first, second):\r\n\r\n    num1 = 0\r\n    num2 = 0\r\n\r\n    first_ptr = first.head\r\n    second_ptr = second.head\r\n    \r\n    while first_ptr != None or second_ptr != None:\r\n        if first_ptr != None:\r\n            num1 = (num1 * 10) + first_ptr.data\r\n            first_ptr = first_ptr.next\r\n    \r\n        if second_ptr != None:\r\n            num2 = (num2 * 10) + second_ptr.data\r\n            second_ptr = second_ptr.next\r\n    \r\n    return num1 * num2\r\n\r\n# Driver code\r\nif __name__=='__main__':\r\n\r\n    first = LinkedList()\r\n    second = LinkedList()\r\n\r\n    first.push(1)\r\n    first.push(6)\r\n    first.push(5)\r\n\r\n    print(\"First list is: \", end = '')\r\n    first.printList()\r\n\r\n    second.push(2)\r\n    second.push(4)\r\n\r\n    print(\"Second List is: \", end = '')\r\n    second.printList()\r\n\r\n    result = multiplyTwoLists(first, second)\r\n    print(\"Result is: \", result)\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_4332 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_4332 a\"),jQuery(\"#tab-content_4332\"));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<h3>Output<\/h3>\n<p>List one is: 5\u21926\u21921<br \/>\nList two is: 4\u21922<br \/>\n<br \/>Answer: 23562<\/p>\n<p><strong>Time Complexity to multiply two numbers represented by linked lists:<\/strong> O(N+M), where N and M are lengths of the input linked lists.<\/p>\n<p>In this blog, we have tried to explain the algorithm and approach for multiply two numbers represented by Linked Lists. This problem is interesting as well as important from the interviewee\u2019s point of view. Also, you can solve the problems regarding the 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<table width=\"641\">\n<tbody>\n<tr>\n<td colspan=\"2\" width=\"641\" style=\"text-align: center\"><strong>Related Articles<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/doubly-circular-linked-list-introduction-and-insertion\/\">Doubly circular linked list in data structure<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/advantages-disadvantages-and-uses-of-a-doubly-linked-list\/\">Application of doubly linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/applications-of-linked-list-data-structure\/\">Applications of linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/difference-between-a-singly-linked-list-and-a-doubly-linked-list\/\">Singly linked list vs doubly linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/advantage-and-disadvantage-of-linked-list-over-array\/\">Advantages and disadvantages of linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/menu-driven-program-for-all-operations-on-doubly-linked-list-in-c\/\">Doubly linked list all operations in C<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/binary-search\/binary-search-on-linked-list\/\">Binary search in linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/bubble-sort-for-linked-list-by-swapping-nodes\/\">Bubble sort linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/delete-a-node-in-doubly-linked-list\/\">Deletion in doubly linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/delete-middle-of-linked-list\/\">Delete the middle node of a linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/adding-two-polynomials-using-linked-list\/\">Polynomial addition using linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/find-the-smallest-and-largest-elements-in-a-singly-linked-list\/\">Find max value and min value in linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/insert-a-node-at-a-specific-position-in-a-linked-list\/\">Insert a node at a specific position in a linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/swap-nodes-in-a-linked-list-without-swapping-data\/\">Swap nodes in linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/add-two-numbers-represented-by-linked-lists-set-1\/\">Add two numbers represented by linked lists<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/find-the-first-node-of-the-loop-in-a-linked-list\/\">Find starting point of loop in linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/merge-sort-on-a-singly-linked-list\/\">Merge sort linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/delete-a-node-at-a-given-position\/\">Delete a node from linked list at a given position<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/remove-duplicates-from-an-unsorted-linked-list\/\">Remove duplicates from unsorted linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/python\/python-program-to-reverse-a-linked-list\/\">Reverse a linked list in Python<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Conclusion<\/strong><br \/>\nMultiplying two numbers represented by linked lists can be achieved by first traversing both lists to form the actual numbers to be multiplied. Once the numbers are obtained, perform the multiplication operation and return the resulting product. This process involves careful handling of linked list nodes, appropriate arithmetic operations, and attention to edge cases.<\/p>\n<h2>FAQs related to how to multiply two numbers represented by linked lists<\/h2>\n<p>Below are some FAQs related to multiply two linked lists<br \/>\n<strong>Q1. What does it mean to represent numbers using linked lists?<\/strong><br \/>\nRepresenting numbers using linked lists involves breaking down each number digit by digit and storing each digit in a separate node of a linked list. The least significant digit is typically stored in the first node, and the most significant digit is stored in the last node.<\/p>\n<p><strong>Q2. How do you convert a linked list representation back to a numerical value?<\/strong><br \/>\nTo convert a linked list representation back to a numerical value, traverse the linked list from the head to the tail, extracting each digit, and then combine the digits to form the final numerical value.<\/p>\n<p><strong>Q3. How do you handle multiplication of large numbers using linked lists?<\/strong><br \/>\nWhen dealing with large numbers, multiplication using linked lists can become computationally expensive. In such cases, optimized algorithms like Karatsuba or Fast Fourier Transform (FFT) can be employed to improve the efficiency of the multiplication operation.<\/p>\n<p><strong>Q4. What are the main steps involved in multiplying two numbers represented by linked lists?<\/strong><br \/>\nThe main steps involve traversing both linked lists to obtain the numerical values, performing the multiplication operation, and returning the product. Proper consideration should be given to edge cases like leading zeros and handling negative numbers if applicable.<\/p>\n<p><strong>Q5. Can linked list multiplication handle decimal numbers?<\/strong><br \/>\nWhile the process described in this context applies to integer multiplication, linked lists can be modified to support multiplication of decimal numbers. This typically involves representing the fractional part as a separate linked list and handling the multiplication and addition of fractional digits.<\/p>\n<p><strong>Q6. How do you deal with leading zeros in linked list multiplication?<\/strong><br \/>\nLeading zeros are typically ignored during multiplication, as they do not affect the final product. However, when converting the linked list representation back to a numerical value, leading zeros should be excluded to obtain the correct result.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article aims to demonstrate how to multiply two numbers represented by linked lists. In this problem, we are given two linked lists, L1 and L2. Both L1 and L2 are numbers represented as linked lists. We are required to multiply these Lists and produce the output. Let\u2019s take a look at how to multiply [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[125],"tags":[],"class_list":["post-4331","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 two numbers represented by Linked Lists<\/title>\n<meta name=\"description\" content=\"Learn the most efficient way to multiply two numbers represented as Linked Lists. This blog explains the algorithm for multiplying two numbers represented as 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\/multiply-two-numbers-represented-by-linked-lists\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Multiply two numbers represented by Linked Lists\" \/>\n<meta property=\"og:description\" content=\"Learn the most efficient way to multiply two numbers represented as Linked Lists. This blog explains the algorithm for multiplying two numbers represented as Linked Lists.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-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-25T09:40:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-24T05:31:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-1-l1.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=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/\"},\"author\":{\"name\":\"PrepBytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e\"},\"headline\":\"Multiply two numbers represented by Linked Lists\",\"datePublished\":\"2021-08-25T09:40:32+00:00\",\"dateModified\":\"2023-07-24T05:31:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/\"},\"wordCount\":1030,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-1-l1.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/\",\"name\":\"Multiply two numbers represented by Linked Lists\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-1-l1.png\",\"datePublished\":\"2021-08-25T09:40:32+00:00\",\"dateModified\":\"2023-07-24T05:31:42+00:00\",\"description\":\"Learn the most efficient way to multiply two numbers represented as Linked Lists. This blog explains the algorithm for multiplying two numbers represented as Linked Lists.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/#primaryimage\",\"url\":\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-1-l1.png\",\"contentUrl\":\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-1-l1.png\",\"width\":595,\"height\":100},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-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 two numbers represented by 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\/39fcf072e04987f16796546f2ca83c2e\",\"name\":\"PrepBytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g\",\"caption\":\"PrepBytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/prepbytes\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Multiply two numbers represented by Linked Lists","description":"Learn the most efficient way to multiply two numbers represented as Linked Lists. This blog explains the algorithm for multiplying two numbers represented as 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\/multiply-two-numbers-represented-by-linked-lists\/","og_locale":"en_US","og_type":"article","og_title":"Multiply two numbers represented by Linked Lists","og_description":"Learn the most efficient way to multiply two numbers represented as Linked Lists. This blog explains the algorithm for multiplying two numbers represented as Linked Lists.","og_url":"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-08-25T09:40:32+00:00","article_modified_time":"2023-07-24T05:31:42+00:00","og_image":[{"url":"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-1-l1.png","type":"","width":"","height":""}],"author":"PrepBytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"PrepBytes","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/"},"author":{"name":"PrepBytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e"},"headline":"Multiply two numbers represented by Linked Lists","datePublished":"2021-08-25T09:40:32+00:00","dateModified":"2023-07-24T05:31:42+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/"},"wordCount":1030,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-1-l1.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/","url":"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/","name":"Multiply two numbers represented by Linked Lists","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-1-l1.png","datePublished":"2021-08-25T09:40:32+00:00","dateModified":"2023-07-24T05:31:42+00:00","description":"Learn the most efficient way to multiply two numbers represented as Linked Lists. This blog explains the algorithm for multiplying two numbers represented as Linked Lists.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-linked-lists\/#primaryimage","url":"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-1-l1.png","contentUrl":"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-1-l1.png","width":595,"height":100},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/multiply-two-numbers-represented-by-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 two numbers represented by 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\/39fcf072e04987f16796546f2ca83c2e","name":"PrepBytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g","caption":"PrepBytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/prepbytes\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/4331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=4331"}],"version-history":[{"count":8,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/4331\/revisions"}],"predecessor-version":[{"id":17308,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/4331\/revisions\/17308"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=4331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=4331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=4331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}