JPMorgan ChaseOA #8
Distinct Digit Numbers
Estimated MediumJudge-ready
Topics (AI-labelled)Prefix & RangesBits & Math
For each closed range of positive integers, count the integers whose decimal representation has no repeated digit. For the original example [9,84] the answer should be 69; the original 47 is wrong, and its list omits 84.
Input
The first line contains q, followed by q lines of lower upper. Original bound 1≤q≤100000; the original upper bound on the endpoints is truncated, so this site adds 1≤lower≤upper≤1000000.
Output
Output q lines of counts, one for each closed range in order.
Example 1
Input:
2
1 20
9 19
Output:
19
10
Example 2
Input:
5
7 8
52 80
9 84
57 64
74 78
Output:
2
26
69
8
4
Example 3
Input:
1
80 120
Output:
27
Example notes
The outputs of the three public examples are, in order: 19 / 10; 2 / 26 / 69 / 8 / 4; 27. These answers have been checked by independent enumeration or direct simulation.
Editorial
Loading solution…