ExamAdda Logo

Add Two Numbers

Easy

You are given two non-empty linked lists representing two non-negative integers.

The digits are stored in reverse order, and each node contains a single digit.

Add the two numbers and return the sum as a linked list.

The numbers do not contain leading zeros, except for the number 0.

Example 1

Input

3
2 4 3
3
5 6 4

Output

7 0 8

Explanation

The lists represent:

342 + 465 = 807

 

Since the digits are stored in reverse order, the result is:

7 -> 0 -> 8

Example 2

Input

2
9 9
1
1

Output

0 0 1

Explanation

The lists represent:

99 + 1 = 100

 

Therefore, the result is:

0 -> 0 -> 1

Constraints

1 <= number of nodes in each linked list <= 100
0 <= Node.val <= 9
The numbers represented by the linked lists do not contain leading zeros.

Hints:

Hint 1

Traverse both linked lists simultaneously while maintaining a carry.

Hint 2

At each position:

sum = digit1 + digit2 + carry

digit = sum % 10

carry = sum / 10

Author & Technical Reviewer

ExamAdda Technical Review Team

Technically reviewed by: ExamAdda Technical Review Team

Technical Reviewers, ExamAdda

Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.

Published

Aug 10, 2026

Last updated

Aug 11, 2026

Content Verification Methodology

Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.

Report a correction:editorial@examadda.org
Auto
Loading editor...
Input

Expected Output