Asked at 10 companies
5 recent
- Bloomberg
- Meta
- Amazon
- Microsoft
- Intuit
- Capgemini
- Zoho
- tcs
- Visa
Community-reported · source · updated 2026-11-18. ● asked in the last 6 months.
Go step by step: try it yourself before the video and the visual. Progress saves on this device.
0 / 110 pointsSolved (Easy) 0/20Reviews 0/50Mastered 0/25Practice steps 0/15
Step 1
Know these before you start
Practise each one here, or tick what you already know
Step 2
Try it on paper
5–10 minutes, no code yet
In the wild · File permissions: Unix stores read, write and execute as three bits, so chmod 755 is just bits: 7 = 111 (rwx), 5 = 101 (r-x).
ProblemProblem statementYou are given a large integer represented as an array of digits, most significant first. Increment it by one and return the resulting array of digits.ReadHide
Problem Statement
You are given a large integer represented as an array of digits, most significant first. Increment it by one and return the resulting array of digits.
Added 2026-10-30 from Srujan's LeetCode solved list (photo) — not previously in the repo.
Input / Output
Input: digits = [1,2,3]
Output: [1,2,4]
Input: digits = [4,3,2,1]
Output: [4,3,2,2]
Input: digits = [9]
Output: [1,0]
Input: digits = [9,9]
Output: [1,0,0]
Code it here
Tab / Shift+Tab indent · ⌘/Ctrl+/ comments · ⌘/Ctrl+Enter runs · Esc leaves the editor
Step 6
Get it accepted
All test cases pass
Step 7
Review it so it sticks
Re-solve from memory after
The step that matters most: without reviews most of a solved problem fades within weeks. Three short re-solves, each just as you start to forget, are what make it yours.
Your notes
Three lines in your own words. They come back with this problem's reviews, so you can check yourself after recalling the solution.
Solve it yourself before you look
Reading the solution first feels like progress, but it makes the next similar problem — and the interview version — much harder, because you skipped the part where you figure it out. Give it an honest 20–30 minutes. Stuck? Re-read the pattern, watch the concept video, or try the brute force first.
Hidden: approach · solution code · optimal solution
Approach
Pattern Recognition
Scan from Right with Carry — adding 1 only ever touches the last digit, unless it is a 9. A 9 becomes 0 and the carry moves left; if every digit is 9, the answer needs one extra digit at the front.
Approach
Brute Force — Convert, Add, Convert Back, O(n)
number = int("".join(digits)) # whole number at once
number += 1
return [int(c) for c in str(number)]
Works for small inputs, but the whole point of the array form is that the number can be too big for a native integer — and it hides the carry idea.
Optimized — Carry from the Right, O(n)
for i from n-1 down to 0:
if digits[i] < 9:
digits[i] += 1
return digits # carry stops here
digits[i] = 0 # 9 + 1 = 0, carry on
return [1] + digits # all 9s: 999 + 1 = 1000
Complexity
| Approach | Time | Space | Notes |
|---|---|---|---|
| Convert to int | O(n) | O(n) | Overflows / hides the idea |
| Carry from right | O(n) | O(1) extra | Only the all-9s case grows |
Solution code
from typing import List
class SolutionBruteForce:
"""O(n) time | O(n) space — convert to an int, add 1, convert back."""
def plusOne(self, digits: List[int]) -> List[int]:
number = int("".join(str(d) for d in digits)) + 1
return [int(c) for c in str(number)]
class Solution:
"""O(n) time | O(1) extra space — carry from the right."""
def plusOne(self, digits: List[int]) -> List[int]:
for i in range(len(digits) - 1, -1, -1):
if digits[i] < 9:
digits[i] += 1
return digits
digits[i] = 0
return [1] + digitsOther ways to solve it
- Thought of another approach (slower, or cleverer)? Code it here: the same tests check any approach.
- Community solutions on LeetCode ↗ for many more versions, in many languages. Read them after you've solved it.
Revising this one?
- →Solve it from memory before peeking
- →Say the pattern out loud, not just the code
- →Explain it like you would to a friend
- →Try it again in a different language