Sequential Digits - Problem

An integer has sequential digits if and only if each digit in the number is one more than the previous digit.

Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.

Example: The number 234 has sequential digits because 2→3→4 where each digit is exactly one more than the previous. The number 235 does NOT have sequential digits because 3→5 skips 4.

Input & Output

Example 1 — Basic Range
$ Input: low = 100, high = 300
Output: [123,234]
💡 Note: 123 has sequential digits (1→2→3), 234 has sequential digits (2→3→4). No other numbers in range [100,300] have sequential digits.
Example 2 — Wider Range
$ Input: low = 1000, high = 13000
Output: [1234,2345,3456,4567,5678,6789,12345]
💡 Note: All 4-digit sequential numbers (1234-6789) and the 5-digit number 12345 fall within this range.
Example 3 — Single Digits
$ Input: low = 1, high = 10
Output: [1,2,3,4,5,6,7,8,9]
💡 Note: All single digits from 1-9 have sequential digits by definition (only one digit).

Constraints

  • 10 ≤ low ≤ high ≤ 109

Visualization

Tap to expand
Sequential Digits: Find Numbers with Consecutive Digit Patternlow = 100high = 3001232341242351→2→3 ✓2→3→4 ✓1→2→4 ✗2→3→5 ✗Output: [123, 234]
Understanding the Visualization
1
Input Range
Given low=100, high=300
2
Check Pattern
Find numbers where digits go n, n+1, n+2, ...
3
Output
Return [123, 234] - both have sequential digits
Key Takeaway
🎯 Key Insight: Only 36 sequential digit numbers exist total - generate them all instead of checking every number in range
Asked in
Google 15 Amazon 12 Microsoft 8
25.0K Views
Medium Frequency
~15 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen