Count how many integers in a range satisfy digit-wise constraints on their decimal representation.
You are given two integers start and finish, a maximum allowed digit limit, and a string s representing a suffix.
Count the integers x such that:
start <= x <= finishx is at most limitx ends with the string sReturn the number of such integers.
The intended challenge is to efficiently count valid numbers in a numeric range without iterating through every integer one by one.
start: lower bound of the rangefinish: upper bound of the rangelimit: maximum allowed digit values: required suffix as a decimal string[start, finish] that satisfy all conditions.0 <= start <= finish1 <= limit <= 9s contains only decimal digitsExample 1
Input
start = 1, finish = 200, limit = 4, s = "2"
Output
10
Explanation
Valid numbers are 2, 12, 20, 21, 22, 32, 42, 102, 112, and 122.
Example 2
Input
start = 10, finish = 1000, limit = 5, s = "5"
Output
25
Explanation
Count all numbers in the range whose digits are all at most 5 and that end in 5.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.