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
Integer Break: Finding Maximum Product (n = 8)Input: 8Break into k≥2 partsTry Different Splits:• 1+7 → 1×7 = 7• 2+6 → 2×6 = 12• 3+3+2 → 3×3×2 = 18 ✓• 2+2+2+2 → 2×2×2×2 = 16Output: 18Maximum ProductKey insight: Use mostly 3s for optimal product-to-sum ratio332××= 18
Understanding the Visualization
1
Input
Integer n that must be broken into k≥2 parts
2
Process
Find optimal way to split for maximum product
3
Output
Maximum possible product
Key Takeaway
🎯 Key Insight: Use mostly 3s because 3 gives the best product-to-sum ratio for maximizing the final product
Asked in
Google 15 Amazon 12 Facebook 8
182.0K Views
Medium Frequency
~25 min Avg. Time
3.2K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen