Given a range of numbers [l, r] and an integer q. 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 q.
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 l to r to generate all numbers in the range and convert each such number n and it’s product with q, i.e. n*q 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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count unequal element pairs from the given Array
- Minimize count of unequal elements at corresponding indices between given arrays
- Minimum replacements to make adjacent characters unequal in a ternary string
- Minimum replacements to make adjacent characters unequal in a ternary string | Set-2
- XOR two binary strings of unequal lengths
- Minimum replacements in a string to make adjacent characters unequal
- Minimum digits to be removed to make either all digits or alternating digits same
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- Find the number in a range having maximum product of the digits
- Count of Numbers in Range where the number does not contain more than K non zero digits
- Maximum product from array such that frequency sum of all repeating elements in product is less than or equal to 2 * k
- Numbers with a Fibonacci difference between Sum of digits at even and odd positions in a given range
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Count of largest sized groups while grouping according to product of digits
- Count of integers of length N and value less than K such that they contain digits only from the given set
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Maximum sum and product of the M consecutive digits in a number
- Count of binary strings of length N having equal count of 0's and 1's and count of 1's ≥ count of 0's in each prefix substring
- Count number of indices such that s[i] = s[i+1] : Range queries
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.