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 Software Developer Intern Interview Questions Asked at Josh Technology Group
Q. Given a linked list, how do you ensure that it is in decreasing order?
Q. Given a random node in a BST, how do you check if a given element is part of the...read more
Q. Merge Two Binary Trees Problem Statement You are given the roots of two binary t...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for Josh Technology Group Software Developer Intern
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
C++ Interview Questions and Answers
150 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

