Integer Break
MediumGreedy
Description
Given an integer n, break it into at least two positive integers and maximize the product of those integers. Return the result as an integer.
Examples
Input:
n = 10Output:
36Explanation:
10 = 3 + 3 + 4, product = 36
Input:
n = 4Output:
4Explanation:
4 = 2 + 2, product = 2 × 2 = 4. One could also break it as 4 = 1 + 3 with product = 3, or 4 = 1 + 1 + 2 with product = 2, but 2 + 2 gives the maximum product of 4.
Input:
n = 7Output:
12Explanation:
7 = 3 + 4, product = 3 × 4 = 12. Alternative breakdowns like 7 = 2 + 2 + 3 give product = 12, and 7 = 3 + 2 + 2 also gives product = 12. Other options like 7 = 1 + 6 (product = 6) or 7 = 2 + 5 (product = 10) yield smaller products.
Constraints
- •
2 ≤ n ≤ 58