Add two numbers represented by linked lists
Submissions: 27626   Accuracy:

30.12%

  Difficulty: Easy   Marks: 2

Given two numbers represented by two linked lists of size N and M. The task is to return a sum list. The sum list which is list representation of addition of two input numbers.

Input:
First line of input contains number of testcases T. For each testcase, first line of input contains length of first linked list and next line contains N elements of the linked list. Again, next line contains M, and following line contains M elements of the linked list.

Output:
Output the resultant linked list.

User Task:
The task is to complete the function addTwoLists() which has node reference of both the linked lists and returns the head of new list.

Constraints:
1 <= T <= 100
1 <= N, M <= 100

Example:
Input:
2
2
4 5
3
3 4 5
2
6 3
1
7

Output:
0 9 3 
0 7

Explaination:
5->4 // linked link repsentation of 4 5.
5->4->3 // linked list representation of 3 4 5
.
0->9 ->3 // linked list representation of 3 9 0 resultant linked list.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Amit Khandelwal
Author: bhawnamait


Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.