Add Two Numbers
A medium Linked List problem included in Apna College, Love Babbar 450, Striver A2Z. Below: the roles whose interviews prioritise this topic, and how to practise it.
- Topic
- Linked List
- Sheets
- 3
- Core for
- 3 roles
- Platform
- LeetCode
The problem
Add two numbers represented by two linked lists where digits are stored in reverse order, and return the sum as a linked list.
Example 1
- Input
- l1=[2,4,3], l2=[5,6,4]
- Output
- [7,0,8]
Example 2
- Input
- l1=[0], l2=[0]
- Output
- [0]
Example 3
- Input
- l1=[9,9,9,9,9,9,9], l2=[9,9,9,9]
- Output
- [8,9,9,9,0,0,0,1]
Constraints
- 1 <= list length <= 100
- 0 <= Node.val <= 9
How to think about it
Updated 2026-09-09Storing digits in reverse order is a gift: head nodes represent the least significant digit, which is exactly where grade-school addition starts. You can march forward through both lists simultaneously, maintaining a carry digit without ever reversing either list.
Approaches, worst first
Integer conversion
time O(max(m, n)) · space O(max(m, n))
Convert both linked lists into native integer types, sum them, and reconstruct a new linked list from the digits. Fails on inputs longer than 15-20 digits due to integer overflow limits.
Iterative digit simulation with dummy headWrite this one
time O(max(m, n)) · space O(max(m, n))
Traverse both lists alongside a carry accumulator. At each step, sum the active digits and carry, append a new node containing `sum % 10` to the result list, update `carry = Math.floor(sum / 10)`, and advance non-null pointers. Loop until both lists and the carry are exhausted.
Where people lose marks · 3
- Forgetting to check the carry after both lists have been fully traversed misses the final most significant digit (for instance 5 + 5 producing [0] instead of [0, 1]).
- Assuming both lists share identical lengths leads to null dereferences when one list outlasts the other; missing digits must default to 0.
- Converting node values to numbers directly fails on lists with up to 100 digits where standard numeric types lose precision or overflow.
The theory behind it
Linked List — the ground this problem stands on. All Linked List problems
What Linked List is
A linked list is a chain of separate cargo cars connected by coupling hooks, scattered anywhere across memory rather than sitting in a tidy contiguous row. Each car, called a node, holds a single piece of data and a pointer directing traffic to the address of the next car in line. Because nodes connect only by directional links, jumping straight to the tenth car is impossible without walking past the first nine.
When to reach for it
Choose a linked list when a problem requires frequent insertions and deletions at known positions without shifting whole blocks of surrounding memory. Problems mentioning pointer splicing, reversing subsequences in place, merging sorted streams, or detecting cycles in linear chains strongly point here. It is ideal when total capacity is unpredictable and memory allocation must happen one individual node at a time.
How the pattern works
Think in terms of pointer rewiring before dereferencing. Keep a dummy head node pointing to the start of the list so modifications to the initial item do not require separate edge logic. Always save references to neighboring nodes into temporary variables before cutting or redirecting forward links. When diagnosing loops or locating middle nodes, advance two references simultaneously at differing velocities so traversal completes without supplementary storage.
What each operation costs
| Operation | Time |
|---|---|
| insert or delete at the head | O(1) |
| insert or delete after a known node | O(1) |
| find an element by value or position | O(n) |
What usually goes wrong with Linked List
- Losing access to the remainder of the chain by overwriting a next reference before caching the downstream node address in a temporary variable.
- Attempting to read properties of a null node reference after walking one step beyond the tail or advancing a fast runner without checking its next step.
- Creating an accidental infinite cycle by pointing a trailing node back into earlier segments of the chain without severing old outgoing links.
Which roles need this problem
Linked List is a core topic for these 3 roles — if you're targeting one of them, this problem is early in your path, not optional.
Secondary for 5 more roles, including Full-Stack Developer, Android Developer, iOS Developer.
Track this in your role's order
Pick your target role and all 370 problems — including this one — resequence to what that interview actually asks. Free.
Start freeMore Linked List problems
Problem set and role mapping as of .