Strobogrammatic Number III - Problem
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).
Given two strings low and high that represent two integers where low <= high, return the number of strobogrammatic numbers in the range [low, high].
The digits that remain the same when rotated 180 degrees are: 0, 1, 6, 8, 9 where:
- 0 → 0
- 1 → 1
- 6 → 9
- 8 → 8
- 9 → 6
Input & Output
Example 1 — Small Range
$
Input:
low = "50", high = "100"
›
Output:
3
💡 Note:
Strobogrammatic numbers in range [50,100] are: 69, 88, 96. Each looks the same when rotated 180°.
Example 2 — Single Digit Range
$
Input:
low = "0", high = "9"
›
Output:
3
💡 Note:
Single digit strobogrammatic numbers are: 0, 1, 8. Numbers 2,3,4,5,6,7,9 don't look the same when rotated.
Example 3 — No Valid Numbers
$
Input:
low = "20", high = "30"
›
Output:
0
💡 Note:
No strobogrammatic numbers exist between 20 and 30.
Constraints
- 1 ≤ low.length, high.length ≤ 15
- low and high consist of only digits
- low ≤ high
- low and high do not contain any leading zeros except for zero itself
Visualization
Tap to expand
Understanding the Visualization
1
Input Range
Given low="50" and high="100"
2
Check Numbers
Find numbers that look same when rotated 180°
3
Count Valid
Return count of strobogrammatic numbers in range
Key Takeaway
🎯 Key Insight: Generate valid strobogrammatic numbers recursively instead of checking every number in range
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code