Multiply Linked Lists
Given two numbers represented by linked lists. Your task is to find the multiplied list and return the head of the multiplied list.
The multiplied list is a linked list representation of the multiplication of two numbers.
Input Format:
The first line of input contains a single integer T, representing the number of test cases or queries to be run.
Then the T test cases follow.
The first line of each test case contains the elements of the first singly linked list separated by a single space and terminated by -1. Hence, -1 would never be a list element.
The second line of each test case contains the elements of the second singly linked list separated by a single space and terminated by -1. Hence, -1 would never be a list element.
Output Format:
For each test case, print the multiplied linked list. The elements of the multiplied list should be single-space separated, terminated by -1.
The output of each test case is printed in a separate line.
Note :
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 10
1 <= N, M <= 100
0 <= data <= 9
Where N and M are the number of nodes in the two linked lists.
Time Limit: 1 sec
official_Hemant
4mo
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!
Add answer anonymously...
Top Josh Technology Group Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
>
Josh Technology Group Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app