Given an integer N > 0, the task is to find the maximum product of digits among numbers less than or equal to N.
Input: N = 390
Maximum possible product is given by the number 389
3 * 8 * 9 = 216
Input: N = 432
Approach: This problem can also be solved using the method described in this article taking lower limit as 1 and upper limit as N. Another method to solve this problem is by using recursion. The conditions for recursion are as follows:
- If N = 0 then return 1.
- If N < 10 then return N.
- Otherwise, return max(maxProd(N / 10) * (N % 10), maxProd((N / 10) – 1) * 9
At each step of recursion, either the last digit or 9 is taken to maximize the product of digit.
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.
- Find the maximum sum of digits of the product of two numbers
- Find the number in a range having maximum product of the digits
- Find four factors of N with maximum product and sum equal to N | Set 3
- Find four factors of N with maximum product and sum equal to N
- Find four factors of N with maximum product and sum equal to N | Set-2
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Smallest number k such that the product of digits of k is equal to n
- Check if product of digits of a number at even and odd places is equal
- Number of digits in the product of two numbers
- Sort the numbers according to their product of digits
- Cumulative product of digits of all numbers in the given range
- Maximum of sum and product of digits until number is reduced to a single digit
- Count different numbers that can be generated such that there digits sum is equal to 'n'
- Count of N digit Numbers whose sum of every K consecutive digits is equal | Set 2
- Count of N digit Numbers whose sum of every K consecutive digits is equal
- Count of numbers whose sum of increasing powers of digits is equal to the number itself
- Find a Number X whose sum with its digits is equal to N
- Find the first N integers such that the sum of their digits is equal to 10
- Find a number x such that sum of x and its digits is equal to given n.
- Find the minimum positive integer such that it is divisible by A and sum of its digits is equal to B
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.