Add Two Numbers
On this page
Problem statement
Two non-negative integers are stored as linked lists of digits, lowest digit first. Return their sum as a list in the same format. Each node holds one digit 0–9. The numbers have no leading zeros, except the number 0 itself, which is a single node
[0].
A classic warm-up that still filters out many candidates: the logic is grade-school addition, and the score comes from handling the carry and lists of different lengths without special cases. Original problem: LeetCode 2.
Example

Input: l1 = [2, 4, 6], l2 = [9, 7, 8] # 642 + 879
Output: [1, 2, 5, 1] # 1521
Input: l1 = [9, 9], l2 = [1] # 99 + 1
Output: [0, 0, 1] # 100
Constraints (assumed)
- Each list has 1 to 100 nodes, so the numbers can be far larger than 64 bits.
- Node values are 0–9.
What this question tests
- Walking two lists of different lengths in one loop.
- Carrying correctly, including the carry left over at the end.
- Using a dummy head so the first node needs no special case.
Questions to ask first
- Are the digits stored lowest first? (Here: yes. The reversed order is a separate variant.)
- Can I convert the lists to integers? Not in languages with fixed-size integers, since 100 digits overflow; and it misses the point anyway.
- May I modify the input lists, or must I build a new one? (Here: build a new one.)
- Can the lists be empty? (Here: no, each has at least one node.)
Try it yourself first
You have the full problem. Sketch your answer, then sign up free to read the complete walkthrough.
- The complete design, flow by flow, with pictures
- Deep dives into the hard parts
- What mid, senior and staff candidates are expected to say
- Full company question lists
Free forever. No card needed.