Problem Statement
Plus One
You are given a big number, but instead of one normal number it is written out one digit at a time inside an array. For example, the array digits = [1,2,3] means the number 123. The digits go from the biggest place value on the left to the smallest place value on the right, just like how we write numbers. Your job is to add 1 to this number and give back the new array of digits. So [1,2,3] should become [1,2,4].
Signals to notice
Brute force first
Convert to number, add 1, convert back — fails for very large numbers. It is a fair place to begin because it matches the surface of the question, yet it does not capture the deeper structure that makes the problem simpler.
The key insight
Process right to left, handle carry. The goal is not to be clever for its own sake, but to remember the one relationship that keeps the solution grounded as you move forward.
Trace it on digits=[9]
Start: digits=[9], scan right-to-left from i=0 i=0: digits[0]=9, not < 9 -> set digits[0]=0, carry continues. digits=[0] Loop ends (no index left) without returning -> carry escaped the array All digits were 9, so prepend a leading 1: [1] + [0] = [1,0] Return [1,0]
What must stay true
Carry propagates leftward; stop as soon as there's no carry. If that remains true after every update, the rest of the reasoning has a stable place to stand.
Shape of the loop
for i from last index down to 0:
if digits[i] < 9:
digits[i] += 1
return digits # no carry, done
digits[i] = 0 # was 9 -> becomes 0, carry left
return [1] + digits # all 9s: prepend leading 1Pseudocode only — the full worked solution lives in the Solution tab.
Easy way to go wrong
Forgetting the case where all digits are 9 (999 → 1000) — need to prepend a 1. The fix is usually to return to the meaning of each move, not just the steps themselves.