Count numbers with digit gap

Write codeHard35 min

Your task

Count how many integers in the inclusive range [1, n] have the property that every pair of adjacent decimal digits differs by at least 2 (i.e. |d_i - d_{i+1}| >= 2 for all consecutive digits, reading the number with no leading zeros). Single-digit numbers trivially qualify since they have no adjacent pair. Return the count. 1 <= n <= 10^9.

Examples

count_diff_at_least_two(n: int) -> int
Example 1
Inputcount_diff_at_least_two(20)
Output17