Skip to main content
Back to problems
Leetcode
Medium
Arrays
Math
Strings
1291. Sequential Digits

Generate all integers in a range whose digits form consecutive increasing sequences.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.

Sequential Digits

gfg
Problem Statement

Given two integers low and high, return all integers in the inclusive range [low, high] such that every digit in the number is exactly one greater than the previous digit.

A number like 1234 is sequential, while 135 or 1223 is not.

Return the results in increasing order.

Input Format

  • Two integers low and high.
  • Find every integer x such that low <= x <= high and the digits of x are strictly consecutive increasing by 1.

Output Format

  • Return a list of all valid integers in ascending order.

Constraints

  • 10 <= low <= high <= $10^{9}$
  • Each valid number must use digits from 1 to 9 without repetition.
  • The answer size is finite and small because sequential numbers can only be formed from contiguous digit runs.
Examples
Sample cases returned by the problem API.

Example 1

Input

low = 100, high = 300

Output

[123,234]

Explanation

The sequential-digit numbers in this range are 123 and 234.

Example 2

Input

low = 1000, high = 13000

Output

[1234,2345,3456,4567,5678,6789,12345]

Explanation

Each number is made of consecutive increasing digits and falls within the range.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.