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 :
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Check if N can be expressed as product of 3 distinct numbers
- Check whether a number can be expressed as a product of single digit numbers
- Sum of M maximum distinct digit sum from 1 to N that are factors of K
- Count of N-digit numbers with all distinct digits
- Count numbers with exactly K non-zero digits and distinct odd digit sum
- Integers from the range that are composed of a single distinct digit
- Count numbers whose maximum sum of distinct digit-sum is less than or equals M
- Check if frequency of each digit is less than the digit
- Product of N with its largest odd digit
- Digit - Product - Sequence
- Distinct Prime Factors of Array Product
- Find distinct integers for a triplet with given product
- Count all distinct pairs with product equal to K
- Product of non-repeating (distinct) elements in an Array
- Find two distinct prime numbers with given product
- First digit in product of an array of numbers
- Largest palindrome which is product of two n-digit numbers
- Maximum number with same digit factorial product
- Last digit of Product of two Large or Small numbers (a * b)
- Largest palindrome which is product of two N-digit numbers : Set 2
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.