7. Plus One
easyAsked at VercelGiven an array of digits representing a non-negative integer, add one and return the result as an array. Vercel uses this as a 'do you handle carries cleanly' screen — the same skill you need to bump build numbers or version tags in their deployment graph.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Vercel loops.
- Glassdoor (2025-11)— Vercel screen for new grads; carry propagation expected.
- LeetCode Discuss (2026-Q1)— Mentioned in Vercel interview prep guide.
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. Increment the integer by one and return the resulting array of digits.
Constraints
1 <= digits.length <= 1000 <= digits[i] <= 9digits does not contain any leading 0s.
Examples
Example 1
digits = [1,2,3][1,2,4]Example 2
digits = [9][1,0]Explanation: 9 + 1 = 10.
Example 3
digits = [9,9,9][1,0,0,0]Approaches
1. Convert to BigInt, add, convert back
Join digits into a string, parse as BigInt, add 1n, split into digits.
- Time
- O(n)
- Space
- O(n)
function plusOne(digits) {
const n = BigInt(digits.join('')) + 1n;
return String(n).split('').map(Number);
}Tradeoff: Works but dodges the algorithm. Some interviewers reject this because they want to see the carry logic.
2. In-place carry propagation (optimal)
Walk right-to-left. If digit < 9, increment and return. If digit == 9, set to 0 and continue. If we fall off the front, prepend 1.
- Time
- O(n)
- Space
- O(1) when no extra digit; O(n) when [9,9,...,9]
function plusOne(digits) {
for (let i = digits.length - 1; i >= 0; i--) {
if (digits[i] < 9) {
digits[i]++;
return digits;
}
digits[i] = 0;
}
return [1, ...digits];
}Tradeoff: Early return on the first non-9 digit makes the average case O(1) amortized. The only allocation happens when input is all 9s.
Vercel-specific tips
Vercel grades the in-place carry logic and the early-return optimization. Bonus signal: explaining that the only case requiring a new array is when the input is all 9s, and that this generalizes to base-N arithmetic, which they use in build-number versioning. Avoid the BigInt shortcut unless they explicitly say it's allowed.
Common mistakes
- Forgetting the all-9s case — returns `[0,0,0]` for input `[9,9,9]` instead of `[1,0,0,0]`.
- Iterating left-to-right — carries propagate right-to-left, this just doesn't work.
- Mutating digits AND building a new array — wasteful; pick one and stick with it.
Follow-up questions
An interviewer at Vercel may pivot to one of these next:
- Add Two Numbers as linked lists (LC 2) — same carry pattern in a different shape.
- Multiply Strings (LC 43) — generalized carry-and-shift.
- Add Strings (LC 415) — same problem with two operands instead of one.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why right-to-left?
Carries propagate from the least significant digit upward, exactly the way we add by hand. Going left-to-right would require a second pass to fix the carry chain.
Why not use Array.unshift(1)?
unshift is O(n) on most engines because it shifts every existing element. The spread `[1, ...digits]` is equivalent but reads more cleanly; either works.
Practice these live with InterviewChamp.AI
Drill Plus One and other Vercel interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →