Plus One
Real-world version: Wheel Counter TickThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def plus_one(digits: list[int]) -> list[int]:public int[] plusOne(int[] digits)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's