Link: https://leetcode.com/problems/sequential-digits/
Solution:
Topics: sliding window
Intuition
This is kind of an interesting problem. If the digits must be strictly increasing, then all digits within any interval can be formulated by moving a window over the string '123456789'
. Generating all possible increasing digits is thus only an n**3
operation where n=9
…this is almost negligible.
Implementation
Mnemonic
All valid sequential numbers with strictly increasing digits exist as a subarray in '123456789'
Visual
Review 1
My implementation above is kind of weird. Seems simpler just to do a left, right sliding window.