Given a range of numbers [l, r] and an integer . The task is to count all such number in the given range such that any digit of the number does not match with any digit in its product with the given number .
Input : l = 10, r = 12, q = 2 Output : 1 10*2 = 20 which has 0 as same digit 12*2 = 24 which as 2 as same digit 11*2 = 22 no same digit Input : l = 5, r = 15, q = 2 Output : 9
Source : Goldman Sachs Interview set 46
The idea is to run a loop from to to generate all numbers in the range and convert each such number and it’s product with q, i.e. to strings using to_string() method and then check if any character in string2 is present in string1 or not using basic string hashing.
Below is the implementation of the above approach:
- Count of Numbers in Range where the number does not contain more than K non zero digits
- Find the number in a range having maximum product of the digits
- Count Unary Numbers in a Range
- Count of Numbers in a Range where digit d occurs exactly K times
- Count of Numbers in a Range divisible by m and having digit d in even positions
- Count numbers in a range having GCD of powers of prime factors equal to 1
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Count of Numbers in Range where first digit is equal to last digit of the number
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Maximum sum and product of the M consecutive digits in a number
- Numbers less than N which are product of exactly two distinct prime numbers
- Numbers within a range that can be expressed as power of two numbers
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Count numbers < = N whose difference with the count of primes upto them is > = K
- Count all sub-sequences having product <= K - Recursive approach
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.