Skip to content
Decoder

Plus One

Easy

Problem

A large non-negative integer is stored as a list of digits, most significant first, with no leading zeros (except the number 0 itself). Add one to it and return the new list of digits.

Example 1

Input
digits = [1, 2, 3]
Output
[1, 2, 4]

Example 2

Input
digits = [1, 9, 9]
Output
[2, 0, 0]

Example 3

Input
digits = [9, 9, 9]
Output
[1, 0, 0, 0]

Constraints

  • 1 <= digits.length <= 100
  • 0 <= digits[i] <= 9
  • digits has no leading zeros, except for the number 0 itself.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.