487. Minimum Factorization
Given a positive integer num, return the smallest positive integer x whose multiplication of each digit equals num. If there is no answer or the answer is not fit in 32-bit signed integer, return 0.
Example 1:
Input: num = 48
Process:
We need to find the smallest integer x whose digits multiply to 48.
- Factorizing 48: 48 = 8 × 6 ,
- Other possibilities: 48 = 2 × 2 × 2 × 2 × 3, but forming a number from these digits will result in a larger value.
The smallest possible number that satisfies the condition is 68 (since digits 6 and 8 are arranged in ascending order to form the smallest possible number).
Output: 68
Example 2:
Input: num = 15
Process:
We need to find the smallest integer x whose digits multiply to 15.
- Factorizing 15: 15 = 5 × 3
- The digits 3 and 5 can form 35, which is the smallest valid number.
Arranging the digits in ascending order gives 35.
Output: 35
Now Your Turn!
Pick the correct output for the given inputInput : num = 18
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= num <= 231 - 1