Skip to main content

Plus One Linked List - Solution & Explanation

MediumPremiumFree on FleetCodeLinked ListMath8 min readAsked at: Amazon, Google
Practice this problem

Problem Statement

Given a non-negative integer represented as a linked list of digits, plus one to the integer.

The digits are stored such that the most significant digit is at the head of the list.

 

Example 1:

Input: head = [1,2,3]
Output: [1,2,4]

Example 2:

Input: head = [0]
Output: [1]

 

Constraints:

  • The number of nodes in the linked list is in the range [1, 100].
  • 0 <= Node.val <= 9
  • The number represented by the linked list does not contain leading zeros except for the zero itself. 

Approach Overview

Problem Overview: A non‑negative integer is stored as a singly linked list where each node contains a single digit. The most significant digit appears first. Add one to the number and return the updated list while correctly handling carry propagation such as 1→2→9 becoming 1→3→0.

Approach 1: Reverse List + Add One (O(n) time, O(1) space)

Reverse the linked list so the least significant digit becomes the head. Perform the usual digit addition: add 1, propagate carry while digits equal 9, and stop once no carry remains. If a carry still exists after the final node, append a new node with value 1. Reverse the list again to restore the original order. This mirrors how addition works from right to left but requires two list reversals.

Approach 2: Recursion Carry Propagation (O(n) time, O(n) space)

Use recursion to reach the tail node first. When the recursive call returns, propagate the carry back toward the head. Each step updates node.val = (node.val + carry) % 10 and forwards (node.val + carry) / 10. If the head still produces a carry, prepend a new node with value 1. The logic is clean and closely models mathematical addition, but recursion consumes O(n) call stack space.

Approach 3: Last Non‑9 Traversal (O(n) time, O(1) space)

This is the optimal single‑pass technique. Traverse the list and track the last node whose value is not 9. Increment that node by one, then set every node after it to 0. If the list contains only 9s (for example 9→9→9), create a dummy node with value 0 before the head. After incrementing the dummy, the result becomes 1→0→0→0. This avoids reversing the list and avoids recursion while handling carry efficiently.

The key insight relies on how carry works in base‑10 numbers. Only the rightmost non‑9 digit actually changes; every trailing 9 becomes 0. Recognizing this pattern allows a single traversal using standard linked list iteration combined with simple math rules.

Recommended for interviews: The last non‑9 traversal approach. It runs in O(n) time with O(1) space and demonstrates strong understanding of carry propagation in linked lists. Reverse‑and‑add shows solid fundamentals, but the single‑pass technique is what most interviewers expect for a polished solution.

Solution

We first set a dummy head node dummy, initially with a value of 0, and the successor node of dummy is the linked list head.

Next, we traverse the linked list starting from the dummy head node, find the last node that is not 9, increment its value by 1, and set the values of all nodes after this node to 0.

Finally, we check if the value of the dummy head node is 1. If it is 1, we return dummy; otherwise, we return the successor node of dummy.

The time complexity is O(n), where n is the length of the linked list. The space complexity is O(1).

Code

Python

Java

C++

Go

TypeScript

Try this approach in the editor →

Detailed Complexity Analysis

ApproachTimeSpaceWhen to Use
Reverse List + Add OneO(n)O(1)When you want straightforward digit addition similar to array problems
Recursion Carry PropagationO(n)O(n)When recursion is acceptable and code clarity is preferred
Last Non-9 TraversalO(n)O(1)Optimal approach for interviews and production due to single traversal and constant memory

Video Solution

Leetcode 369. Plus One Linked List PythonTechZoo644 views views

Watch 5 more video solutions →

Frequently Asked Questions

Is Plus One Linked List easy or hard?
Plus One Linked List is generally classified as a medium difficulty problem. The main challenge is correctly handling carry when multiple trailing digits are 9, especially without reversing the list or using extra memory.
Plus One Linked List Python/Java solution
Python and Java implementations typically follow the last non‑9 traversal technique. Track the rightmost non‑9 node during iteration, increment it, and reset subsequent digits to zero. This produces an O(n) time and O(1) space solution.
How to solve Plus One Linked List in O(n)?
Traverse the list and remember the last node whose value is not 9. After the traversal, increment that node by one and set all nodes after it to 0. If every digit was 9, prepend a dummy node with value 0 and perform the same update, producing a new leading 1.
What is the best approach for Plus One Linked List?
The best approach is the last non‑9 traversal method. Traverse the linked list while tracking the rightmost node whose value is not 9. Increment that node and set all following digits to 0. This solves the problem in O(n) time with O(1) extra space without reversing the list.
Is Plus One Linked List asked at Google/Amazon/Meta?
Plus One Linked List is a common linked list interview problem that appears in preparation sets used by companies like Google, Amazon, and Meta. It tests understanding of carry propagation, linked list traversal, and edge case handling such as consecutive 9s.
What data structure is used in Plus One Linked List?
The problem uses a singly linked list where each node stores a single digit of a number. Efficient solutions rely on pointer traversal, carry handling, and simple mathematical digit operations.
What is the time complexity of Plus One Linked List?
The optimal solution runs in O(n) time because you must traverse the linked list at least once to find the last non‑9 digit. Space complexity can be O(1) with an iterative traversal or O(n) if recursion is used due to the call stack.

Ready to solve this problem?

Practice Plus One Linked List with our built-in code editor and test cases.

Practice on FleetCode