66. Plus One
easyAsked at JPMorganIncrement by one a non-negative integer represented as a digit array. JPMorgan asks this on Software Engineer Programme phone screens as a low-cognitive-load problem that grades carry-propagation correctness and edge-case handling on a leading 9.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in JPMorgan loops.
- Glassdoor (2026-Q1)— JPMorgan SDE phone-screen reports list this as a recurring warm-up.
- LeetCode (2026-Q1)— Tagged JPMorgan on the LeetCode company tag page.
- Blind (2025-11)— JPMC SWE-I write-up cites Plus One as the carry-propagation warm-up before Add Strings on the onsite.
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: Carry propagates and grows the array by one.
Example 4
digits = [9,9,9][1,0,0,0]Approaches
1. Walk from the least significant digit with carry (optimal)
Walk right-to-left. Add 1 to the last digit; while it overflows (== 10), set to 0 and carry 1 into the next-left digit. If the leftmost still carries, prepend 1.
- Time
- O(n)
- Space
- O(1) extra (output reuses input)
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: O(n) worst case (all nines), O(1) amortised when the last digit is not 9 because the loop returns immediately. Provably optimal — every algorithm must at minimum look at the last digit.
2. BigInt conversion
Join digits to a string, parse to BigInt, add 1, format back to digits.
- Time
- O(n)
- Space
- O(n)
function plusOneBig(digits) {
const n = BigInt(digits.join('')) + 1n;
return n.toString().split('').map(Number);
}Tradeoff: Works but heavier — allocates strings and a BigInt. JPMorgan interviewers explicitly note this as a 'do not do this on the whiteboard' approach because it dodges the carry-handling skill they are grading.
JPMorgan-specific tips
JPMorgan interviewers ask this because the carry-propagation pattern shows up in Add Strings (LC 415), Add Binary (LC 67), and Add Two Numbers (LC 2), which they ask as follow-ups. State 'I will walk from the least significant digit and propagate carries, growing the array only if the leftmost carries' before coding — that one sentence proves you have seen the pattern.
Common mistakes
- Forgetting the [1, ...digits] prepend when all digits are 9 — silently truncates the result.
- Reading the array left-to-right (most significant first) instead of right-to-left — incorrect carry semantics.
- Trying to handle the carry with a separate variable when an early-return on 'digit < 9 after increment' is cleaner.
- Using digits.unshift(1) instead of [1, ...digits] — same result but O(n) shift cost on top of the existing O(n) walk.
Follow-up questions
An interviewer at JPMorgan may pivot to one of these next:
- Add Strings (LC 415) — same pattern but two operands.
- Add Binary (LC 67) — base 2 instead of base 10.
- Add Two Numbers (LC 2) — same pattern but on linked lists.
- What if the digits represent a number in base k for some k > 10?
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why walk right-to-left instead of left-to-right?
Carry only propagates from less-significant to more-significant digits. Walking right-to-left lets you write each updated digit in place and stop as soon as you find a digit that does not carry. Walking left-to-right would require an extra pass to know whether the right side carries up to you.
Is there a way to avoid the array-grow on [9,9,9]?
Not in general — the result has one more digit than the input, so the array must grow by exactly one slot. The early-return optimisation handles every other case in O(1) amortised; only the all-nines worst case allocates.
Free learning resources
Curated free links for this problem.
Practice these live with InterviewChamp.AI
Drill Plus One and other JPMorgan interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →