Sequential Digits
Real-world version: Staircase Serial Numbers In A WindowThe statement here is our own: the same inputs, outputs and technique.
A parts catalogue reserves a special shape of serial number for its display models. A staircase serial is a positive integer of two or more digits in which each digit is exactly one more than the digit to its left. 45, 678 and 23456 are staircase serials; 55, 321 and 1357 are not, and neither is anything containing a 0, since no digit is one more than 9.
Given an inclusive window [low, high], return every staircase serial that falls inside it, listed from smallest to largest. Return an empty list when the window holds none.
Examples
Example 1
- Input
- low = 1000, high = 13000
- Output
- [1234, 2345, 3456, 4567, 5678, 6789, 12345]
Six four-digit staircase serials sit inside the window, and 12345 is the only five-digit one below 13000.
Example 2
- Input
- low = 5678, high = 9012
- Output
- [5678, 6789]
The lower end of the window is itself a staircase serial and so counts; 6789 is the only other one before the window closes.
Example 3
- Input
- low = 100, high = 110
- Output
- []
The three-digit serials of this shape are 123 and up, so nothing in the window qualifies and the list comes back empty.
Example 4
- Input
- low = 45, high = 45
- Output
- [45]
The window is a single value and 5 is one more than 4, so that value is the whole answer.
Constraints
- 10 <= low <= high <= 10^9
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 staircase_serials(low: int, high: int) -> list[int]:public List<Integer> staircaseSerials(int low, int high)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 8 test cases: 8 passed
- Passed: 4 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
More on the same topics
- Smallest Divisible Digit Product IReal-world version: Next Shelf LabelEasy
- Find the PeaksReal-world version: Ridge Points Along the ProfileEasy
- Finding 3-Digit Even NumbersReal-world version: Three-Digit Even Numbers From the TilesEasy
- Divide an Array Into Subarrays With Minimum Cost IReal-world version: Cutting the Conveyor Into Three StretchesEasy