Problem · Array
Add One to a Number Represented as Digits
Learn this problemProblem statement
You are given a non-empty integer array digits representing a non-negative decimal integer. The most significant digit appears first, and each array element is one digit.
Add one to the represented integer and return the resulting digit array. Do not convert the entire input to a numeric type or use a dynamic list.
The input has no leading zero unless it represents zero itself.
Function
plusOne(digits: int[]) → int[]Examples
Example 1
digits = [1,2,9]return = [1,3,0]Example 2
digits = [9,9,9]return = [1,0,0,0]The carry creates a new most-significant digit.
Constraints
1 <= digits.length <= 2000000 <= digits[i] <= 9digits[0] != 0unlessdigits.length = 1
More Oracle problems
- Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Jul 2026
- Top K Frequent Elements with Larger-Value Tie BreakONSITE INTERVIEW · Seen Jul 2026
- Merge k Sorted ListsPHONE SCREEN · Seen Jul 2026
- Implement a Queue Using Two StacksPHONE SCREEN · Seen Jul 2026
- First Balanced Removal IndexOA · Seen Dec 2025
- Find Circle NumberOA · Seen Oct 2024
- Create Lexicographically Largest PermutationOA · Seen Sep 2024
- Array Reduction 1OA · Seen Feb 2024