Add Two Numbers

Asked byAmazonAppleFacebookMicrosoftBloombergGoogle

Problem

Given two non-empty linked lists representing two non-negative integers with digits stored in reverse order (one digit per node), add the two numbers and return the sum as a linked list in the same reversed-digit format.

Examples

Example 1
Input:l1 = [2,4,3], l2 = [5,6,4]
Output:[7,0,8]
342 + 465 = 807.
Example 2
Input:l1 = [9,9], l2 = [1]
Output:[0,0,1]
99 + 1 = 100.

Constraints

  • 1 <= number of nodes per list <= 100
  • Each digit is 0-9.

Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.

Solve on FeatCode →

How to approach it: the Linked List pattern

A chain of nodes, each pointing to the next. No random access like an array, but insertion and deletion at a known position is O(1), and many classic problems come down to careful pointer rewiring.

Look for this pattern when

  • The problem explicitly gives you a linked list (reverse it, merge lists, detect a cycle, reorder it).
  • You need O(1) insertion/deletion without shifting elements, unlike an array.

Read the full Linked List guide →

Video walkthroughs

Original problem on LeetCode ↗

More Linked List problems