Integer Break - 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.
Input & Output
Example 1 — Basic Case
$
Input:
n = 10
›
Output:
36
💡 Note:
Break 10 into 3+3+2+2. Product = 3×3×2×2 = 36. This is optimal because we use mostly 3s with 2s to handle the remainder.
Example 2 — Small Number
$
Input:
n = 4
›
Output:
4
💡 Note:
Break 4 into 2+2. Product = 2×2 = 4. Alternative 1+3 gives product 3, and 1+1+2 gives product 2, so 2+2 is optimal.
Example 3 — Edge Case
$
Input:
n = 2
›
Output:
1
💡 Note:
Must break into k>=2 parts, so 2 = 1+1. Product = 1×1 = 1. This is the only valid way to break n=2.
Constraints
- 2 ≤ n ≤ 58
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code