Given a number N, the task is to check if the all sub-numbers of this number have distinct digit product.
- An N digit number has N*(N+1)/2 sub-numbers. For example, all possible sub-numbers of 975 are 9, 7, 5, 97, 75, 975.
- Digit product of a number is product of its digits.
Input : N = 324 Output : YES Sub-numbers of 324 are 3, 2, 4, 32, 24 and 324 and digit products are 3, 2, 4, 6, 8 and 24 respectively. All the digit products are different. Input : N = 323 Output : NO Sub-numbers of 323 are 3, 2, 3, 32, 23 and 323 and digit products are 3, 2, 3, 6, 6 and 18 respectively. Digit products 3 and 6 have occurred twice.
- Make a digit array i.e., an array with its elements as digits of given number N.
- Now finding sub-numbers of N is similar to finding all possible subarrays of the digit array.
- Maintain a list of digit products of these subarrays.
- If any digit product has appeared more than once, print NO.
- Else print YES.
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 of N-digit numbers having digit XOR as single digit
- Count of N-digit numbers with all distinct digits
- Check if frequency of each digit is less than the digit
- Find the number of distinct pairs of vertices which have a distance of exactly k in a tree
- Count ways to partition a string such that both parts have equal distinct characters
- Count numbers from 1 to n that have 4 as a digit
- Count divisors of n that have at-least one digit common with n
- Count pairs in an array which have at least one digit common
- Longest subarray such that adjacent elements have at least one common digit | Set 1
- Longest subsequence such that adjacent elements have at least one common digit
- Longest subarray such that adjacent elements have at least one common digit | Set - 2
- Maximum subset sum such that no two elements in set have same digit in them
- Count of numbers in range which are divisible by M and have digit D at odd places
- Check if N can be expressed as product of 3 distinct numbers
- Count all distinct pairs with product equal to K
- Check whether a number can be expressed as a product of single digit numbers
- Sum and Product of all even digit sum Nodes of a Singly Linked List
- Maximum product from array such that frequency sum of all repeating elements in product is less than or equal to 2 * k
- Integers from the range that are composed of a single distinct digit
- Sum of M maximum distinct digit sum from 1 to N that are factors of K
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.