Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Add Two Numbers

Medium
linked-listmathrecursion

Two non-empty linked lists represent non-negative integers with digits stored in reverse order (ones digit first). Add them and return the sum as a linked list in the same format.

Input

  • Line 1: digits of the first number (reverse order)
  • Line 2: digits of the second number (reverse order)

Output: digits of the sum, reverse order, space-separated.

Example 1
Input:
2 4 3
5 6 4
Output:
7 0 8

342 + 465 = 807.

Example 2
Input:
0
0
Output:
0
Example 3
Input:
9 9 9 9 9 9 9
9 9 9 9
Output:
8 9 9 9 0 0 0 1

Constraints

  • 1 ≤ each list's length ≤ 100
  • 0 ≤ digit ≤ 9; no leading zeros except the number 0.
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.