Minimum Factorization - Problem
The Digital Factorization Challenge
Given a positive integer
The Goal: Find the minimum number
Special Cases:
• If no such number exists, return
• If the answer exceeds 32-bit signed integer limits, return
Example: For
Given a positive integer
num, your mission is to find the smallest positive integer whose digits, when multiplied together, equal num.The Goal: Find the minimum number
x such that the product of all digits in x equals num.Special Cases:
• If no such number exists, return
0• If the answer exceeds 32-bit signed integer limits, return
0Example: For
num = 48, we need digits that multiply to 48. We could use 6×8=48, giving us 68. But we could also use 4×3×4=48, giving us 344. Since 68 < 344, the answer is 68. Input & Output
example_1.py — Basic Case
$
Input:
num = 48
›
Output:
68
💡 Note:
We need digits whose product is 48. We can factor 48 = 8 × 6. Arranging in ascending order gives us 68, which is the smallest such number.
example_2.py — Single Digit
$
Input:
num = 18
›
Output:
29
💡 Note:
18 = 9 × 2, so we use digits [9, 2]. Arranging in ascending order gives us 29.
example_3.py — Impossible Case
$
Input:
num = 13
›
Output:
0
💡 Note:
13 is prime and > 9, so it cannot be expressed as a product of single digits 2-9. Return 0.
Constraints
- 1 ≤ num ≤ 108
- Return 0 if no solution exists
- Return 0 if result exceeds 32-bit signed integer limit (231 - 1)
Visualization
Tap to expand
Understanding the Visualization
1
Factor with 9
Try to divide by 9 as many times as possible
2
Factor with 8
Then try 8, then 7, etc. down to 2
3
Check remainder
If remainder > 1, impossible to factorize
4
Sort digits
Arrange collected digits in ascending order
5
Form result
Build the final number and check 32-bit limit
Key Takeaway
🎯 Key Insight: Greedily factor with largest possible digits first, then arrange optimally for the minimum result
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code