Given two positive integers L and R which represents a range and two more positive integers d and K. The task is to find the count of numbers in the range where digit d occurs exactly K times.
Input: L = 11, R = 100, d = 2, k = 1
Required numbers are 12, 20, 21, 23, 24, 25, 26, 27, 28, 29, 32, 42, 52, 62, 72, 82 and 92.
Input: L = 95, R = 1005, d = 0, k = 2
Prerequisites : Digit DP
Approach: Firstly, if we are able to count the required numbers upto R i.e. in the range [0, R], we can easily reach our answer in the range [L, R] by solving for from zero to R and then subtracting the answer we get after solving for from zero to L – 1. Now, we need to define the DP states.
In the final recursive call, when we are at the last position if the count of digit d is equal to K, return 1 otherwise return 0.
Below is the implementation of the above approach:
- Count of Numbers in Range where first digit is equal to last digit of the number
- Number of times the given string occurs in the array in the range [l, r]
- Count numbers with unit digit k in given range
- Count of Numbers in a Range divisible by m and having digit d in even positions
- Find all numbers between range L to R such that sum of digit and sum of square of digit is prime
- Count of integers from the range [0, N] whose digit sum is a multiple of K
- Count n digit numbers not having a particular digit
- Queries to count integers in a range [L, R] such that their digit sum is prime and divisible by K
- Find the highest occurring digit in prime numbers in a range
- Element which occurs consecutively in a given subarray more than or equal to K times
- Count different numbers possible using all the digits their frequency times
- Count of numbers appearing in the given ranges at-least K times
- Count of all N digit numbers such that num + Rev(num) = 10^N - 1
- Count numbers from 1 to n that have 4 as a digit
- Count numbers having 0 as a digit
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.