The Sequential Digits interview question asks you to find all integers in the range [low, high] whose digits form a sequential run — each digit is exactly one more than the previous digit. For example, 123, 234, 456789 are sequential-digit numbers. 321 and 135 are not. Return all such numbers in sorted order within the given range.
Apple, Uber, Meta, Amazon, and Google ask this problem because it tests enumeration on a small, well-defined search space. There are only 36 sequential-digit numbers in total (since digits go from 1 to 9, and you can start at any digit with any length from 2 to 9 digits). Generating them all, filtering by range, and returning sorted — rather than scanning the full range — is the key algorithmic insight. It rewards candidates who recognize the enumeration pattern over brute-force iteration.
The pattern is complete enumeration of the bounded search space. Generate all sequential-digit numbers systematically: for each starting digit d from 1 to 9, and for each length l from 2 to 10 - d (so the last digit doesn't exceed 9), build the number by appending consecutive digits. Collect all generated numbers that fall within [low, high]. Sort the result (or generate in sorted order by iterating shorter lengths first). This yields at most 36 candidates — extremely fast.
Generate all sequential-digit numbers:
Filter for low=100, high=300: Candidates in range: 123, 234. Result: [123, 234].
low to high and checking each — O(high - low) can be up to 10^9, far too slow.For the Sequential Digits coding problem, the enumeration interview pattern is the correct approach. The insight: the total space of valid answers is tiny (36 numbers maximum), so generate all candidates and filter. Interviewers at Apple and Meta appreciate when you state the bounded search space size upfront — it immediately signals you won't be scanning billions of numbers. Practice this "generate all valid candidates, then filter" pattern on problems with small, well-structured answer spaces — it avoids over-engineering with complex binary search or DP.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Count the Number of Substrings With Dominant Ones | Medium | Solve | |
| Sum of Number and Its Reverse | Medium | Solve | |
| Collecting Chocolates | Medium | Solve | |
| Minimum Cost to Set Cooking Time | Medium | Solve | |
| Coordinate With Maximum Network Quality | Medium | Solve |