> ## 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.

# Integer Break Python Solution with Tests

> Tested Python solution for LeetCode 343 with 15 pytest cases. Generate a practice environment with lcpy.

LeetCode 343, Medium. Topics: Math, Dynamic Programming. [View on LeetCode](https://leetcode.com/problems/integer-break/description/).

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

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

## Problem

Given an integer `n`, break it into the sum of `k` **positive integers**, where `k >= 2`, and maximize the product of those integers.

Return *the maximum product you can get*.

### Examples

```
Input: n = 2
Output: 1
Explanation: 2 = 1 + 1, 1 * 1 = 1.
```

```
Input: n = 10
Output: 36
Explanation: 10 = 3 + 3 + 4, 3 * 3 * 4 = 36.
```

### Constraints

* 2 \<= n \<= 58

## Solution

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

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n^2)
    # Space: O(n)
    def integer_break(self, n: int) -> int:
        dp = [0] * (n + 1)
        dp[1] = 1

        for target in range(2, n + 1):
            for part in range(1, target):
                dp[target] = max(dp[target], part * (target - part), part * dp[target - part])

        return dp[n]
```

## Complexity

| Time   | Space |
| ------ | ----- |
| O(n^2) | O(n)  |

## Tags

[NeetCode 250](/catalog/neetcode-250), [NeetCode All](/catalog/neetcode).
