Add Two Numbers II
Problem Statement
You are given two numbers. Each one is stored as a linked list, with one digit per node. The most significant digit comes first, so the head holds the biggest place value.
Add the two numbers and return the sum as a new linked list, in the same format.
Leave both input lists exactly as they were when you return. Their values and their order must not change.
l1 and l2, the heads of two singly linked lists of digits.
The head of a linked list holding the sum, most significant digit first.
7243 + 564 = 7807.
Zero plus zero is zero.
99 + 1 = 100. The carry runs all the way to the front and adds a new digit.
- • Each list has between 1 and 100 nodes.
- • 0 ≤ Node.val ≤ 9
- • No leading zeros, except for the number 0 itself.
- • Follow-up: can you do it without changing the input lists?
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
For each column from the right, walk from the head to reach that column's digits
Push the digits of both numbers, then pop them: the top is the ones digit
Flip both lists so the ones digit is first, add from the heads, flip the inputs back
Column addition starts at the ones digit. The lists can only be walked from the head, so for each column, walk from the head to the digit that sits in that column, add the two digits and the carry, and put the new digit in front of the answer. The idea is right, but every column walks the lists again from the start.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Linked List — Reversal translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.