Skip to content
C

Add Two Numbers Using Linked Lists

Mediumjavapythonccppjavascript

Two non-negative integers are represented by linked lists, one digit per node, with the most significant digit first. Add the two numbers and print the digits of the sum, most significant digit first.

Input Format

The first line contains an integer N. The second line contains N space-separated digits (0-9), the digits of number A, most significant first. The third line contains an integer M. The fourth line contains M space-separated digits (0-9), the digits of number B, most significant first.

Output Format

Print the digits of A + B, most significant first, separated by single spaces, with no leading zeros (print 0 if the sum is zero).

Input (stdin)

Output

Run your code to see output here...