Show problems as
Classic problem #1291MediumEnumeration

Sequential Digits

Real-world version: Staircase Serial Numbers In A Window
Tracked in this browser only
Read Sequential Digits on LeetCode(opens in a new tab)

The 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.

Python
def staircase_serials(low: int, high: int) -> list[int]:
Java
public List<Integer> staircaseSerials(int low, int high)