Ctrl K

Add One to a Digit Array

Easy
A large non-negative number is stored in the array digits, one digit per element, most significant first. There are no leading zeros (unless the number is 0 itself). Add one to the number and return the result in the same form, as an array of digits.
Example 1
digits=[7, 0, 5] → [7, 0, 6]

705 + 1 = 706.

Example 2
digits=[2, 9, 9] → [3, 0, 0]

299 + 1 = 300: the carry ripples through both nines.

Example 3
digits=[9, 9] → [1, 0, 0]

99 + 1 = 100, so the answer has one more digit.

Constraints
  • 1 ≤ len(digits) ≤ 100
  • 0 ≤ digits[i] ≤ 9
  • No leading zeros unless the number is 0
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Lost Ticket EasyCorner Stamps on a Table EasyBest Product of Three EasyThe Biggest Triangle on the Board EasyShadows of Block Towers Easy
loading Python…
Input
digits=[7, 0, 5]
Expected
[7, 0, 6]

Run checks the first 3 tests in your browser. Submit checks all 75 tests on the server, hidden ones included.