66. Plus One
easyAsked at Goldman SachsIncrement a non-negative integer represented as an array of digits by one. Goldman Sachs uses Plus One as a warm-up to verify you can handle carry propagation in-place — looks trivial until you hit [9,9,9].
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Goldman Sachs loops.
- Glassdoor (2026-Q1)— Goldman Sachs SWE phone-screen reports list Plus One as a common warm-up.
- LeetCode Discuss (2025-10)— Plus One is in the top-30 of LeetCode's Goldman Sachs company tag.
Problem
You are given a large integer represented as an integer array digits, where each digits[i] is the i-th digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's. Increment the large integer by one and return the resulting array of digits.
Constraints
1 <= digits.length <= 1000 <= digits[i] <= 9digits does not contain any leading 0's.
Examples
Example 1
digits = [1,2,3][1,2,4]Example 2
digits = [4,3,2,1][4,3,2,2]Example 3
digits = [9][1,0]Explanation: All-9s case — the array grows by one.
Example 4
digits = [9,9,9][1,0,0,0]Approaches
1. Walk right-to-left with carry (optimal)
Increment the last digit. If it becomes 10, set to 0 and carry into the previous digit. If we exit the loop with carry, prepend 1.
- Time
- O(n)
- Space
- O(1)
function plusOne(digits) {
for (let i = digits.length - 1; i >= 0; i--) {
if (digits[i] < 9) {
digits[i]++;
return digits;
}
digits[i] = 0;
}
digits.unshift(1);
return digits;
}Tradeoff: O(n) worst case (all-9s), O(1) amortized for typical inputs. The early return on the first non-9 is the optimization Goldman wants — every digit before the rightmost non-9 stays untouched.
2. Convert to BigInt and back
Join the digits into a string, BigInt+1, split back into an array.
- Time
- O(n)
- Space
- O(n)
function plusOneBig(digits) {
const n = BigInt(digits.join('')) + 1n;
return n.toString().split('').map(Number);
}Tradeoff: Cute but defeats the point — the problem exists specifically because you might be in a language without BigInt. Mention it as the production answer and move on.
Goldman Sachs-specific tips
Goldman Sachs is grading three things on this problem: (1) do you handle the [9,9,9] case where the array grows, (2) do you stop iterating once you hit the first non-9 digit, (3) do you avoid full-array operations when you only need to touch the tail. The early return after digits[i] < 9 is the part Goldman is looking for — most candidates do the full iteration even when unneeded.
Common mistakes
- Allocating a new array of length n+1 by default 'just in case' — wasteful when carry doesn't propagate.
- Forgetting to prepend 1 when the all-9s case carries past the leftmost digit.
- Treating the array as a number, doing arithmetic, then converting back — Goldman expects digit-level handling.
Follow-up questions
An interviewer at Goldman Sachs may pivot to one of these next:
- Add Two Numbers represented as linked lists (LC #2) — same carry idea, different data structure.
- Multiply Strings (LC #43) — generalize to multiplication.
- Plus K instead of Plus One — same template with bigger carries possibly cascading further.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why not just convert to number, add 1, convert back?
Because n can have up to 100 digits in this problem (constraint says length up to 100), which is far beyond what a 64-bit integer holds. The whole point is to do arithmetic on arbitrary-length integers represented as digit arrays — a pattern that recurs in BigInt implementations.
Is array.unshift(1) acceptable?
Yes for correctness. Goldman might ask 'can you avoid the O(n) shift?' — and the answer is to return a new array of length n+1 with digits[0] = 1 and the rest 0. Both are accepted; mention the tradeoff.
Free learning resources
Curated free links for this problem.
Practice these live with InterviewChamp.AI
Drill Plus One and other Goldman Sachs interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →