Minimum Factorization - Problem
The Digital Factorization Challenge

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 0

Example: 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
Digital Factorization Processnum = 72Target÷972÷9=8÷88÷8=1Digits: [9,8]Sort → [8,9]Result: 898×9=72 ✓Key Insights:1. Use only digits 2-9 (avoid 0 and 1)2. Prefer larger digits to minimize digit count3. Sort result digits ascending for smallest number
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
Asked in
Google 15 Amazon 12 Microsoft 8 Apple 5
15.6K Views
Medium Frequency
~15 min Avg. Time
485 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen