Loading problem...
Given a positive integer num, your task is to find and return the smallest positive integer whose digits, when multiplied together, equal num.
In other words, if you take each individual digit of the result and compute their product, it should yield the original number num.
If no such number exists (for example, when num has a prime factor greater than 9, making it impossible to represent as a product of single digits), return 0.
Additionally, if the resulting number exceeds the range of a 32-bit signed integer (greater than 2,147,483,647), return 0.
Key Insight: Since we want the smallest number, we should prefer using larger digits (to minimize the number of digits) and arrange them in ascending order from left to right to form the smallest possible value.
num = 4868The digits of 68 are 6 and 8. Their product is 6 × 8 = 48, which equals num. Among all numbers whose digit product equals 48 (such as 86, 268, 2234, etc.), 68 is the smallest.
num = 1535The digits of 35 are 3 and 5. Their product is 3 × 5 = 15. The number 35 is smaller than 53. No single-digit or two-digit number smaller than 35 has a digit product of 15.
num = 1226The digits of 26 are 2 and 6. Their product is 2 × 6 = 12. Alternatives like 34 (3 × 4 = 12) or 43 are larger than 26, making 26 the optimal answer.
Constraints