

Input: ‘N’ = 1, ‘TASKS = [ [1, 20] ]
Output: 19
For the first task, the given range consists of 20 numbers present out of which ‘11’ is the only number that has repeated occurrences of ‘1’ in its decimal representation.
The first line will contain the integer 'T', the number of test cases.
The first line of each test case contains one integer ‘N’ denoting the length of the array.
The next ‘N’ lines of each test case contain 2 integers, [ ‘L’, ‘R’ ] denoting the range (‘L’, ‘R’).
For each test case, print an array consisting of the count of numbers in the given range which has no repeated digits in it for each task.
You don't need to print anything. It has already been taken care of. Just implement the given function.
1 <= ‘T’ <= 10
1 <= ‘N’ <= 1000
1 <= ‘L’ <= ‘R’ <= 10^5
Time Limit: 1 sec
The idea of this approach is to count all the number that has no repeated digits in the range ‘[L, R]’ by iterating on them one by one for each task.
We can create a function that when given a number returns ‘true’ if the number has no repeated digits otherwise ‘false’.
Then we iterate from ‘L’ to ‘R’ and call the function, if it returns true we increment the answer and we will do it for all the tasks and finally print the result.
// The function will return true if the given number ‘X’ has repeated digits or not.
Boolean haveRepeatedDigits(X)
// The function will return the count of numbers in the range ‘[L, R]’ that has no repeated digits for each task.
Int noRepeatedDigits(vecor<int>& tasks):
The idea for this approach is to once precalculate the numbers that have no repeated digits up to the maximum possible value of ‘R’ and store them in some array.
After precalculating we can use the below idea to find the answer for any given range ‘L’ to ‘R’ in constant time.
The idea is to get the count of all the numbers that have no repeated digits in the range ‘[1, R]’ using the precalculation value stored in the array and subtract the count of numbers that has no repeated digits in the range ‘[1, L-1]’.
It is easy to observe how this always works, as it first includes all the numbers having no repeated digits from ‘1’ to ‘R’ and then excludes all the numbers having no repeated digits, that are not in the range ‘L’ to ‘R’ i.e. the numbers that have no repeated digits in the range ‘1’ to ‘L - 1’.
The things we need to take care of while implementing this solution are,
// The function will return if the given number ‘X’ has repeated digits or not.
Boolean haveRepeatedDigits(X)
// The function does the precalculation and returns the ‘precalculatedCount’ array.
vector<int> preCalculate(maxR)
// The function will return the count of numbers in the range ‘[L, R]’ that has no repeated digits for each task.
Int noRepeatedDigits(vector<int>& tasks)