Add Two Numbers Represented by Linked Lists
Your task is to find the sum list of two numbers represented by linked lists and return the head of the sum list.
Explanation:
The sum list should be a linked list representation of the addition of the two numbers.
Input:
The first line of input contains a single integer T, indicating the number of test cases to be processed.
For each test case, there are two lines of input:
- The first line contains the elements of the first linked list, separated by spaces and ending with -1. The -1 is not part of the list elements.
- The second line contains the elements of the second linked list, also separated by spaces and ending with -1.
Output:
For each test case, print the sum linked list with elements separated by spaces and ending with -1.
Each test case should have its output on a new line.
Example:
Input:
2
7 5 9 4 6 -1
8 4 -1
5 6 3 -1
8 4 2 -1
Output:
5 0 0 5 0 -1
1 4 0 6 -1
Constraints:
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 5 * 104
- 0 ≤ data ≤ 9 and data ≠ -1
Note:
You are not required to print anything; return the head of the sum linked list.
Be the first one to answer
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