All problems
0143EasyArrayMath

Wheel Counter Tick

Tracked in this browser only
Write code

Trains the technique from

LeetCode 66Plus One

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 turnstile keeps its running count on a row of mechanical drums, one digit per drum. The array digits reports what the drums currently show, with digits[0] sitting at the far left of the row.

One more person walks through, so the counter ticks up by a single step. A drum showing nine wraps back to zero and nudges the drum to its left; when the leftmost drum wraps, the housing exposes a fresh drum in front of it that now shows one. Give back the drum readings after the tick.

Examples

Example 1

Input
digits = [3, 1, 7]
Output
[3, 1, 8]

The rightmost drum has room to climb, so nothing else on the row moves.

Example 2

Input
digits = [6, 9]
Output
[7, 0]

The rightmost drum wraps to zero and nudges its neighbour from six to seven.

Example 3

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

Every drum wraps, so the housing exposes a new drum in front showing one.

Constraints

  • 1 <= digits.length <= 100
  • 0 <= digits[i] <= 9
  • The reading has no zero drum in front of its first significant drum.

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 plus_one(digits: list[int]) -> list[int]:
Java
public int[] plusOne(int[] digits)
September 7
Apply