Problem Description
Find and return a sorted list of all integers within the range [low, high] that have sequential digits. A number has sequential digits if every digit is exactly 1 greater than the previous digit.
Key Insights
- Sequential digits can only be constructed from the ordered digit string "123456789".
- The length of the candidate numbers is constrained by the number of digits in the low and high bounds.
- There are limited possibilities (at most 36 different sequential digit numbers), so pre-generation by sliding window over "123456789" is efficient.
- Only include candidates that fall within the given range.
Space and Time Complexity
Time Complexity: O(1) – There is a constant upper bound on the number of candidates generated (at most 36). Space Complexity: O(1) – Only a fixed number of variables and candidate numbers are stored.
Solution
The solution involves generating all sequential digit numbers by sliding a window of length L over the pre-defined string "123456789". The window size L varies from the number of digits in low to the number of digits in high. For each candidate number generated, check if it lies within the range [low, high]. If it does, add it to the result list, which is then returned in sorted order. The algorithms use string slicing and integer conversion, and due to the small number of candidates, the approach is optimally efficient.