Addition Of Two Linked List

easy
1. You are given two linked list with N and M nodes representing two non-negative integers.
 2. Each node of a list contains a digit between 0 - 9. You may assume that the integers do not contain any leading zero, except the number 0 itself. The digits are stored such that the most significant digit is at the head of the list.
 3. You have to write a function that adds the two numbers and returns the result as a linked list.
 4. display is a utility function which displays the contents of Linked List, feel free to use it for debugging purposes.
 5. main takes input from the users and creates the Linked List. You can use display to know its contents.
 6. This is a functional problem. 
 7. You have to complete the addTwoNumbers function. It takes as input the heads of the linked lists. It should return the head of the resultant linked list.
 8. Don't change the code of Node, main and display.

Input Format

First line takes N, the number of elements in the first list. Second line takes input N space separated numbers reperesenting elements of the first linked list. Third line takes M, the number of elements in the second list. Fourth line takes input N space separated numbers reperesenting elements of the second linked list. Input is handled for you.

Output Format

Resultant Linked List. Output is handled for you.

Constraints

1 <= N, M <= 1000

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
6 
5 7 8 8 7 9 
4 
1 7 5 8
Output
5 8 0 6 3 7
Previous
Arranging Vowels And Consonants
Next
Circular Linked List

Related Questions