Last Updated: 9 Oct, 2025

Sequential Digits

Moderate
Asked in company
Amazon

Problem statement

An integer is said to have sequential digits if and only if each digit in the number is one greater than the preceding digit. For example, the numbers 123, 4567, and 89 all have sequential digits.


You are given an inclusive integer range [low, high]. Your task is to find all integers within this range that have sequential digits and return them as a sorted list.


Input Format:
The first and only line of input contains two space-separated integers, low and high.


Output Format:
Print a single line containing all the sequential-digit integers in the range [low, high], sorted in ascending order and separated by spaces.

If no such integers exist in the range, print an empty line.


Note:
The number of integers with sequential digits is very small. A highly efficient approach is to generate all possible sequential-digit numbers first and then filter them based on whether they fall within the given range [low, high].