7. Plus One
easyAsked at WiseIncrement a number represented as a digit array — Wise loves this because it directly probes integer-overflow thinking essential for money math.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Problem
You are given a large integer represented as an integer array digits, with the most significant digit first. Increment the integer by one and return the resulting array.
Constraints
1 <= digits.length <= 1000 <= digits[i] <= 9No leading zeros
Examples
Example 1
digits=[1,2,3][1,2,4]Example 2
digits=[9,9,9][1,0,0,0]Approaches
1. Convert to BigInt and back
Join, BigInt+1n, split back.
- Time
- O(n)
- Space
- O(n)
return (BigInt(digits.join(''))+1n).toString().split('').map(Number);Tradeoff:
2. Right-to-left carry
Walk from least significant digit, propagate carry, unshift if needed.
- Time
- O(n)
- Space
- O(1)
function plusOne(d){
for (let i=d.length-1;i>=0;i--){
if (d[i]<9){ d[i]++; return d; }
d[i]=0;
}
d.unshift(1); return d;
}Tradeoff:
Wise-specific tips
Wise grades whether you reach for BigInt-style precision instinctively — silent overflow on money math is the cardinal sin in their codebase.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
Practice these live with InterviewChamp.AI
Drill Plus One and other Wise interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →