
The first line contains ‘T,’ denoting the number of test cases.
The first line of the test case contains two integers, ‘M’ and ‘N,’ denoting the size of the ‘DIGITS’ array and given number.
The second line contains ‘M’ space-separated distinct integers denoting the elements of ‘DIGITS.’
For each test case, a single line should contain an integer that denotes the total possible numbers which are less than or equal to ‘N.’
You do not need to print anything, and it has already been taken care of. Just implement the given function.
1 <= ’T’ <= 10
1 <= ‘M’ <= 9
1 <= ‘N’ <= 10^9
1 <= ‘DIGITS[i]’ <= 9
Where ‘DIGITS’ is sorted in ascending order, and values in the ‘DIGITS’ array are unique.
Time Limit: 1 sec
The main idea is to form all possible numbers and check if it is less than ‘N’ increase the answer by 1.
Algorithm :
Approach:- The main idea is that all possible numbers with digits less than ‘N’ are :-
Algorithm:-