Ctrl K

Staircase Numbers

Medium
Call a number a staircase if each of its digits is exactly one more than the digit before it, like 3456. You are given two integers lo and hi. Return every staircase number in the range [lo, hi], both ends included, in increasing order.
Example 1
lo=40, hi=80 → [45, 56, 67, 78]

In this range the digits climb step by step in 45, 56, 67 and 78.

Example 2
lo=780, hi=2300 → [789, 1234]

The three-digit 789 and the four-digit 1234 fit; the next one, 2345, is already above 2300.

Example 3
lo=90, hi=99 → []

No digit follows 9, and 89 is below 90, so there are no such numbers.

Constraints
  • 10 ≤ lo ≤ hi ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPrimes Below a Bound MediumNext Time From the Same Digits MediumRestore the Lost Point MediumLongest Ridge on the Route MediumShuffle the Digits Into a Power of Two Medium
loading Python…
Input
lo=40, hi=80
Expected
[45, 56, 67, 78]

Run checks the first 3 tests in your browser. Submit checks all 88 tests on the server, hidden ones included.