UtilityGrid Co. issues sequential numeric serial numbers to the smart meters it installs across a city block. To cut down on billing errors caused by a technician mis-keying a serial number, the operations team only trusts a serial if every digit in its decimal representation is different from every other digit in that same number: 4021 is trusted (its digits 4, 0, 2, 1 are all distinct), but 1044 is not (the digit 4 repeats) and 3553 is not (both 3 and 5 repeat). Given a closed range of serial numbers from a to b inclusive, count how many serials in that range are trusted.
A single line containing two integers a and b, separated by whitespace.
Print a single integer: the number of integers n with a <= n <= b such that no digit value occurs more than once in the decimal representation of n.
Example 1
Input
1 20
Expected
19
Explanation
Among 1..20, every number is trusted except 11 (whose two digits are both 1). That leaves 9 trusted single-digit numbers (1-9) plus 10 trusted two-digit numbers (10,12,13,...,20), for a total of 19.
Example 2
Input
100 105
Expected
4
Explanation
100 has digits 1,0,0 (0 repeats) and 101 has digits 1,0,1 (1 repeats), so both are untrusted. 102, 103, 104, and 105 each have three distinct digits, so the trusted count is 4.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →