![]() |
VOOZH | about |
Given two integers L and R, and an array arr[] containing single digit integers, the task is to find all the integers in the range [L, R) consisting of digits from given array of digits.
Examples:
Input: L = 1, R = 100, arr[] = {2, 3, 5, 7}
Output: 20
Explanation: The number between 1 and 100 total integers which are made up with 2, 3, 5, 7 are:
2, 3, 5, 7, 22, 23, 25, 27, 32, 33, 35, 37, 52, 53, 55, 57, 72, 73, 75, and 77. Total 20.Input: L = 50, R = 60, arr[] = 5
Output: 1
Explanation: The only number in range 50 and 60 55.
Approach: The solution to the problem is based on greedy approach by using the below idea:
Traverse each integer in range [L, R) and check if it consists of only given set of digits.
Follow the steps below to solve the problem:
Below is the implementation of the above approach:
20
Time Complexity: O((R-L)*logN)
Auxiliary Space: O(1)