Odometer
InterviewTime limit1sMemory limit128 MB
Count the integers between X and Y whose decimal digits use one repeated digit except for a single different digit.
- Level
Medium5 of 10
- Topics
- Brute force, Combinatorics
- Solved
- No attempts yet
Problem
Farmer John's cows are on a road trip. The car odometer shows an integer mileage value, starting at () miles and ending at () miles. The cows moo whenever the odometer shows an interesting number, including at the start and end of the trip.
After ignoring leading zeros, look at the remaining digits. A number is interesting if exactly one digit differs and every other digit is the same. For example, and are interesting, while and are not.
Count how many times the cows moo during the trip.
Input
- Line 1: two integers and , separated by a space
Output
- Line 1: the number of times the cows moo during the trip
Hint
An interesting number uses exactly two distinct digits, with one digit appearing once and the other digit filling the remaining positions. Values up to fit in a 64-bit integer.