Multiply Linked Lists Problem Statement

Your task is to multiply two numbers represented as linked lists and return the resultant multiplied linked list.

Explanation:

The multiplied list should be a linked list representation of the product of the two numbers. Each node contains a single digit.

Input:

The first line contains an integer T, the number of test cases.
For each test case, the first line contains elements of the first linked list, separated by spaces and terminated by -1.
The second line contains elements of the second linked list, separated by spaces and terminated by -1.

Output:

For each test case, print the linked list representing the product, with elements single-space separated and terminated by -1.

Example:

Input:
2
3 4 2 -1
4 6 5 -1
5 6 -1
7 8 9 -1
Output:
1 5 8 1 0 -1
4 4 2 0 4 -1

Constraints:

  • 1 ≤ T ≤ 10
  • 1 ≤ N, M ≤ 100
  • 0 ≤ data ≤ 9 for any node in the list
  • Time Limit: 1 sec
Note:

You are not required to print anything; it has already been handled. Implement the function as instructed.

AnswerBot
4mo

Multiply two numbers represented as linked lists and return the resultant multiplied linked list.

  • Create a function that takes two linked lists as input and returns the product as a linked list

  • Traverse...read more

official_Hemant
9mo
class solution { public: long long multiplyTwoLists(Node *first, Node *second) { const long long mod = 1000000007; // 1e9 + 7 long long n1 = 0; long long n2 = 0; Node* temp1 = first; Node* temp2 = sec...read more
Help your peers!
Select
Add answer anonymously...

Josh Technology Group Software Developer Intern interview questions & answers

A Software Developer Intern was asked 3mo agoQ. Given a linked list, how do you ensure that it is in decreasing order?
A Software Developer Intern was asked 3mo agoQ. Given a random node in a BST, how do you check if a given element is part of the...read more
A Software Developer Intern was asked Q. Merge Two Binary Trees Problem Statement You are given the roots of two binary t...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked 3mo agoQ1. Given a linked list, how do you ensure that it is in decreasing order?
A Software Developer Intern was asked 3mo agoQ2. Given a random node in a BST, how do you check if a given element is part of the...read more
A Software Developer Intern was asked Q3. Merge Two Binary Trees Problem Statement You are given the roots of two binary t...read more
Josh Technology Group Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits