easyArrayMathArrays & Hashing

Plus One

easyTime: O(n)Space: O(1)

Recognize the pattern

add one to number represented as arrayhandle carryright to left

Brute force idea

If you approach Plus One in the most literal way possible, you get this: 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.

Better approach

A calmer way to see Plus One is this: 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.

Key invariant

The truth you want to protect throughout Plus One is this: 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.

Watch out for

One easy way to drift off course in Plus One is this: 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.

Arrays & Hashing Pattern