Minimum Factorization - Problem

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 does not fit in a 32-bit signed integer, return 0.

Note: The result must be composed of digits 2-9 only (no 0 or 1), and we want the smallest possible number.

Input & Output

Example 1 — Basic Factorization
$ Input: num = 48
Output: 68
💡 Note: 48 = 8 × 6. The digits are [8, 6]. Arranging in ascending order gives 68.
Example 2 — Single Digit
$ Input: num = 9
Output: 9
💡 Note: 9 is already a single digit, so the answer is 9 itself.
Example 3 — No Valid Factorization
$ Input: num = 11
Output: 0
💡 Note: 11 is prime and cannot be factored using digits 2-9, so return 0.

Constraints

  • 1 ≤ num ≤ 231 - 1
  • The result must fit in a 32-bit signed integer

Visualization

Tap to expand
Minimum Factorization ProcessInput48Factor Greedily48 ÷ 8 = 6, 6 ÷ 6 = 1Result68Number to factorizeFactors: [8, 6] → Sort: [6, 8]Smallest arrangementKey Steps: Try digits 9→2, collect factors, sort ascendingWhy 68? 6×8=48 ✓, and 68 < 86
Understanding the Visualization
1
Input
Given number to factorize
2
Factor
Find digit factors 2-9
3
Arrange
Sort factors ascending for minimum result
Key Takeaway
🎯 Key Insight: Factor greedily from largest to smallest digits, then arrange result in ascending order for minimum value
Asked in
Google 15 Amazon 12 Facebook 8
18.5K Views
Medium Frequency
~25 min Avg. Time
456 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