> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Minimum Factorization Python Solution

> Tested Python solution for LeetCode 625 with 14 pytest cases. Generate a practice environment with lcpy.

LeetCode 625, [Medium](/catalog/medium). Topics: [Greedy](/catalog/topics/greedy), [Math](/catalog/topics/math), Prime Factorization. [View on LeetCode](https://leetcode.com/problems/minimum-factorization/description/).

Generate this problem as a practice environment: tested reference solution, 14 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 625   # by problem number
lcpy gen -s minimum_factorization   # by problem name
```

## 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 is not fit in **32-bit** signed integer, return `0`.

### Examples

```
Input: num = 48
Output: 68
```

```
Input: num = 15
Output: 35
```

### Constraints

* `1 <= num <= 2^31 - 1`

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_factorization/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_factorization/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(log(num) * 8)
    # Space: O(log(num))
    def smallest_factorization(self, num: int) -> int:
        if num < 10:
            return num
        digits: list[int] = []
        for d in range(9, 1, -1):
            while num % d == 0:
                num //= d
                digits.append(d)
        if num != 1:
            return 0
        result = 0
        for d in reversed(digits):
            result = result * 10 + d
        return result if result <= 2**31 - 1 else 0
```

## Complexity

| Time | Space |
| - | - |
| O(log(num) \* 8) | O(log(num)) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.