You're working with digit analysis! Given a single-digit integer d (from 0-9) and two integers low and high, your task is to count how many times the digit d appears in all numbers within the inclusive range [low, high].
For example, if you're looking for digit 1 in the range [1, 13], you need to examine each number: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13. The digit 1 appears in: 1 (once), 10 (once), 11 (twice), 12 (once), 13 (once) = 6 times total.
Note: Multi-digit numbers can contain the target digit multiple times (like 11 contains two 1's), and each occurrence should be counted separately.
Input & Output
Visualization
Time & Space Complexity
We iterate through n numbers, and for each number we need O(log n) time to process its digits
Space needed to store string representation of largest number
Constraints
- 0 โค d โค 9 (single digit)
- 1 โค low โค high โค 2 ร 108
- Note: For digit 0, leading zeros are not counted