7. Plus One
easyAsked at ServiceNowGiven a digit array representing a non-negative integer, return the array after adding one. ServiceNow uses this to test carry-propagation hygiene — the same shape they apply when incrementing record version counters in their CMDB.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in ServiceNow loops.
- Glassdoor (2026-Q1)— Bundled in ServiceNow phone-screen warmups for SDE-I roles.
- LeetCode Discuss (2025-12)— Posted as a ServiceNow array-manipulation warmup.
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 zeros. 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 zeros.
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: 9 + 1 = 10.
Approaches
1. Convert to BigInt and back
Join digits to a string, parse to BigInt, add 1, split back to digits.
- Time
- O(n)
- Space
- O(n)
function plusOne(digits) {
const n = BigInt(digits.join('')) + 1n;
return n.toString().split('').map(Number);
}Tradeoff: Works but feels lazy in an interview. ServiceNow expects you to demonstrate carry-propagation logic directly.
2. Right-to-left carry walk
Walk from the last digit. If it's < 9, increment and return. Otherwise set to 0 and continue. If you exit the loop, prepend a 1.
- Time
- O(n)
- Space
- O(1) extra (or O(n) if you must grow)
function plusOne(digits) {
for (let i = digits.length - 1; i >= 0; i--) {
if (digits[i] < 9) {
digits[i]++;
return digits;
}
digits[i] = 0;
}
digits.unshift(1);
return digits;
}Tradeoff: Linear time. Returns early on the common case (last digit < 9), which is the optimization ServiceNow grades for.
ServiceNow-specific tips
ServiceNow grades for the early-exit pattern — they want you to return immediately when the last digit is < 9 instead of always running the full carry walk. Bonus signal: note that the all-9s case requires growing the array (unshift), and call out the O(n) cost of unshift explicitly.
Common mistakes
- Iterating left to right and trying to track carry — possible but messier.
- Forgetting the case where the array grows by one digit (all 9s).
- Mutating digits and returning a sliced copy — wastes memory.
Follow-up questions
An interviewer at ServiceNow may pivot to one of these next:
- Add Binary (LC 67) — same shape with base 2.
- Add Two Numbers (LC 2) — same logic on linked lists.
- Multiply Strings (LC 43) — extends to multiplication.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why walk right to left?
Carry propagates from least significant to most significant, which is the right-to-left direction of the array as stored.
What if the input had leading zeros?
The problem rules that out. If it didn't, you'd still need to strip leading zeros from the result — important for the 'starts with 0' edge case.
Practice these live with InterviewChamp.AI
Drill Plus One and other ServiceNow interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →