8. Plus One
easyAsked at DatabricksGiven a non-empty array of digits representing a non-negative integer, add one to the integer. Databricks asks this to see if you handle the carry-propagation cleanly and whether you reach for in-place mutation when the structure allows.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Databricks loops.
- LeetCode Discuss (2025-09)— Databricks intern phone screen warm-up.
- Glassdoor (2026-Q1)— Sometimes used as the 30-second sanity check before harder problems.
Problem
You are given a large integer represented as an integer array digits, where each digits[i] is the ith 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]Approaches
1. Convert to integer, add, convert back
Parse the array as a number, add 1, split back to digits.
- Time
- O(n)
- Space
- O(n)
function plusOne(digits) {
return String(BigInt(digits.join('')) + 1n).split('').map(Number);
}Tradeoff: Works but relies on BigInt; misses the point of the question.
2. In-place carry propagation from the right
Walk right-to-left. If digit < 9, increment and return. If 9, set to 0 and carry. If all 9s, prepend 1.
- Time
- O(n)
- Space
- O(1) — O(n) only on all-9s case
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: Single pass; early-exits on the common case (no carry chain). The all-9s edge needs the prepend.
Databricks-specific tips
Databricks grades the early-exit pattern — most increments don't carry, so returning immediately on the first non-9 is the signal they want. Don't reach for BigInt; reaching for it tells Databricks you're not comfortable with low-level digit manipulation, which matters for their query-engine numeric code paths. The all-9s edge is worth calling out before you code it.
Common mistakes
- Iterating left-to-right (wrong direction for carry).
- Allocating a new array on every iteration instead of mutating in place.
- Forgetting the all-9s case: [9,9,9] -> [1,0,0,0], not [0,0,0].
Follow-up questions
An interviewer at Databricks may pivot to one of these next:
- Add two arrays of digits (LC 989).
- Multiply two arrays of digits (LC 43).
- What if digits[i] could be any base, not just 10?
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why mutate the input?
Saves allocation and signals you understand when ownership of the array allows it. If the spec requires immutability, copy once and then mutate the copy.
What about negative numbers?
The problem constrains digits to non-negative. Plus one on negatives would need sign handling — different problem.
Practice these live with InterviewChamp.AI
Drill Plus One and other Databricks interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →