Try the Problem
You can practice the problem here:
https://leetcode.com/problems/add-two-numbers/
Problem Description (In Simple Words)
You are given two linked lists, where:
- Each node contains a single digit (0–9)
- The digits are stored in reverse order
👉 That means:
Your task is:
👉 Add these two numbers
👉 Return the result as a linked list (also in reverse order)
Important Points to Understand
- Each node contains only one digit
- Numbers are stored in reverse order
- You must return the answer as a linked list
- You must handle carry just like normal addition
Example Walkthrough
Example 1
Input:
Interpretation:
Output:
Example 2
Input:
Output:
Example 3
Input:
Output:
Constraints
Understanding the Core Idea
This problem is essentially:
👉 Adding two numbers digit by digit
But instead of arrays or integers, the digits are stored in linked lists.
How Addition Works (Real-Life Analogy)
Let’s add:
We normally add from right to left:
Now notice something important:
👉 Linked list is already in reverse order
👉 So we can directly process from left to right
Thinking About the Solution
Before coding, let’s think of possible approaches:
Possible Ways to Solve
- Convert linked lists into numbers → add → convert back (Not safe due to overflow)
- Store digits in arrays and simulate addition
- Traverse both lists and simulate addition directly (best approach)
Optimal Approach: Simulate Addition (Digit by Digit)
Key Idea
We traverse both linked lists and:
- Add corresponding digits
- Maintain a carry
- Create a new node for each digit of result
Step-by-Step Logic
Step 1: Initialize
- Create a dummy node (to simplify result building)
- Create a pointer
currto build the result list - Initialize
carry = 0
Step 2: Traverse Both Lists
Continue while:
At each step:
- Start with carry:
- Add value from
l1(if exists) - Add value from
l2(if exists)
Step 3: Create New Node
- Digit to store:
- New carry:
Step 4: Move Forward
- Move
l1andl2if they exist - Move
currforward
Step 5: Handle Remaining Carry
If carry is not zero after loop:
👉 Add one more node
Step 6: Return Result
Return:
Code Implementation (With Explanation)
Dry Run (Important for Understanding)
Input:
Step-by-step:
Final:
Time Complexity
Where:
n= length of l1m= length of l2
Space Complexity
For storing the result linked list.
Why Dummy Node is Important
Without dummy node:
- You need to handle first node separately
With dummy node:
- Code becomes clean and consistent
- No special cases required
Common Mistakes to Avoid
❌ Forgetting to handle carry
❌ Not checking if l1 or l2 is null
❌ Missing last carry node
❌ Incorrect pointer movement
Key Takeaways
- This is a simulation problem
- Linked list problems become easier with dummy nodes
- Always think in terms of real-world analogy (addition)
Conclusion
The Add Two Numbers problem is one of the most important linked list problems for interviews.
It teaches:
- Pointer manipulation
- Carry handling
- Iterative traversal
- Clean code using dummy nodes
Once you understand this pattern, many other linked list problems become much easier to solve.
👉 Tip: Whenever you see problems involving numbers in linked lists, think of digit-by-digit simulation with carry.




