Double a Number Represented as a Linked List
Problem Statement
You are given the head of a linked list that stores a non-negative whole number. Each node holds one digit, and the most significant digit comes first.
Return the head of a new linked list that stores the number multiplied by 2, in the same format.
head, the first node of a singly linked list of digits. It is never empty.
The head of a linked list holding the doubled number, most significant digit first.
189 × 2 = 378.
999 × 2 = 1998. The carry out of the first digit needs a brand new leading digit.
0 × 2 = 0.
- • The list has between 1 and 10^4 nodes.
- • 0 ≤ Node.val ≤ 9
- • No leading zeros, except for the number 0 itself.
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Copy the digits into an array, double from the last one, build the answer from the front
Flip the list, double each digit with the carry, add a node if a carry is left, flip back
An array can be read from the last index, which is the ones digit. Copy the digits into a vector, then double from the end to the start, carrying as we go. Each new digit goes in front of the answer. A carry left at the end adds one more digit at the front. The answer is right, but every digit gets copied.
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.