All problems
0642EasyArrayMath

Advancing A Digit Strip Counter

Tracked in this browser only
Write code

Trains the technique from

LeetCode 989Add to Array-Form of Integer

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A mechanical counter shows its reading as digits, one decimal digit per wheel, listed from the most significant wheel to the least significant one. The reading carries no leading zero unless it is the single digit 0.

The counter is now advanced by step units. Return the new reading in the same form, most significant digit first and with no leading zero. The strip gains a wheel at the front when the reading needs one.

Examples

Example 1

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

The reading 999 advanced by 1 unit becomes 1000, which needs a fourth wheel, so the strip is [1, 0, 0, 0].

Example 2

Input
digits = [1, 4, 0, 7], step = 93
Output
[1, 5, 0, 0]

The reading 1407 advanced by 93 units becomes 1500, so the strip is [1, 5, 0, 0].

Example 3

Input
digits = [0], step = 10000
Output
[1, 0, 0, 0, 0]

The reading 0 advanced by 10000 units becomes 10000, so four wheels are added at the front.

Constraints

  • 1 <= digits.length <= 10^4
  • 0 <= digits[i] <= 9
  • digits has no leading zero unless it is the single digit 0.
  • 1 <= step <= 10^4

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def add_to_array_form(digits: list[int], step: int) -> list[int]:
Java
public List<Integer> addToArrayForm(int[] digits, int step)
September 7
Apply