8. Plus One
easyAsked at PalantirIncrement a number represented as an array of digits. Palantir asks this to gauge attention to carry propagation, which mirrors how their telemetry counters roll over.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Palantir loops.
- LeetCode Discuss (2025-09)— Palantir warm-up problem in junior FDE screens.
- Glassdoor (2026-Q1)— Mentioned alongside big-number arithmetic question.
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 = [9][1,0]Example 3
digits = [9,9][1,0,0]Approaches
1. Convert to number, add, convert back
Join, parseInt, +1, split. Fails on big numbers.
- Time
- O(n)
- Space
- O(n)
function plusOne(d) {
const n = BigInt(d.join('')) + 1n;
return [...n.toString()].map(Number);
}Tradeoff: Works with BigInt but defeats the point of the problem.
2. Walk right-to-left with carry
Start at the last digit. If <9, increment and return. Otherwise set to 0 and continue. If we fall off the left, prepend a 1.
- Time
- O(n)
- Space
- O(1) (or O(n) if all 9s)
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(1) extra space in the common case. The all-9s case needs one prepended slot.
Palantir-specific tips
Palantir interviewers grade this on whether you exit early when no carry propagates (the if digits[i] < 9 branch) and on whether you handle the all-9s case without allocating until necessary. Mention that this is the same pattern as updating a versioned counter in their ontology — most updates are cheap, but occasionally a boundary forces a structural rewrite.
Common mistakes
- Allocating a new array up front even when no carry propagates — wasteful.
- Forgetting the all-9s case — returning [0,0,0] when digits was [9,9,9].
- Using unshift in a loop — O(n^2) due to repeated shifts.
Follow-up questions
An interviewer at Palantir may pivot to one of these next:
- Add two numbers represented as arrays of digits.
- Same problem but the digits are in a linked list (LC 369).
- Multiply two numbers represented as strings (LC 43).
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 propagates from least significant to most significant. Walking right-to-left lets you stop as soon as you hit a non-9 digit, which is the typical case.
Why is prepending only safe at the end?
Inside the loop, you don't know yet whether the carry will fully propagate. Only when you exit the loop with carry still active do you know you need a new MSB.
Practice these live with InterviewChamp.AI
Drill Plus One and other Palantir interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →