Ctrl K

Smallest Number From Digit Factors

Medium
You are given a positive integer product. Find the smallest positive integer whose digits multiply to exactly product. If no such number exists, or it is larger than 2³¹ − 1, return 0.
Example 1
product=36 → 49

4 · 9 = 36, and no smaller number has that digit product (66 and 94, for example, are larger).

Example 2
product=100 → 455

4 · 5 · 5 = 100; two digits cannot multiply to 100.

Example 3
product=26 → 0

26 = 2 · 13, and 13 cannot be built from digits, so the answer is 0.

Constraints
  • 1 ≤ product ≤ 2³¹ − 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsOne Digit Swap MediumLargest Number With Non-Decreasing Digits MediumFewest Guests by Lanyard Color MediumUp or Down for Every Post MediumDouble or Decrement Medium
loading Python…
Input
product=36
Expected
49

Run checks the first 3 tests in your browser. Submit checks all 52 tests on the server, hidden ones included.