Count Stepping Numbers in Range - Problem
Given two positive integers low and high represented as strings, find the count of stepping numbers in the inclusive range [low, high].
A stepping number is an integer such that all of its adjacent digits have an absolute difference of exactly 1.
Return an integer denoting the count of stepping numbers in the inclusive range [low, high].
Since the answer may be very large, return it modulo 109 + 7.
Note: A stepping number should not have a leading zero.
Input & Output
Example 1 — Basic Range
$
Input:
low = "0", high = "21"
›
Output:
13
💡 Note:
Stepping numbers in [0,21]: 0,1,2,3,4,5,6,7,8,9,10,12,21. Count = 13
Example 2 — Single Digit Range
$
Input:
low = "1", high = "9"
›
Output:
9
💡 Note:
All single digits 1-9 are stepping numbers. Count = 9
Example 3 — Larger Range
$
Input:
low = "10", high = "15"
›
Output:
2
💡 Note:
Stepping numbers in [10,15]: 10,12. Count = 2
Constraints
- 1 ≤ low.length, high.length ≤ 15
- low and high consist of only digits
- low ≤ high
- low and high don't have leading zeros
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code