Integer Break - Problem

You're given a positive integer n, and your task is to break it into the sum of at least 2 positive integers such that the product of those integers is maximized.

For example, if n = 8, you could break it as:

  • 8 = 1 + 7 → product = 1 × 7 = 7
  • 8 = 2 + 6 → product = 2 × 6 = 12
  • 8 = 3 + 5 → product = 3 × 5 = 15
  • 8 = 2 + 3 + 3 → product = 2 × 3 × 3 = 18 ✓ (maximum!)

Your goal is to find the maximum possible product you can achieve by breaking the integer optimally.

Input & Output

example_1.py — Basic Case
$ Input: n = 2
Output: 1
💡 Note: 2 = 1 + 1, and the product is 1 × 1 = 1
example_2.py — Optimal Split
$ Input: n = 10
Output: 36
💡 Note: 10 = 3 + 3 + 2 + 2, and the product is 3 × 3 × 2 × 2 = 36. Alternative: 10 = 4 + 3 + 3 gives 4 × 3 × 3 = 36
example_3.py — Edge Case
$ Input: n = 4
Output: 4
💡 Note: 4 = 2 + 2, and the product is 2 × 2 = 4. Note that 4 = 1 + 3 gives 1 × 3 = 3, which is smaller

Constraints

  • 2 ≤ n ≤ 58
  • You must break n into at least 2 positive integers
  • All integers in the sum must be positive

Visualization

Tap to expand
Integer Break: Finding Maximum ProductExample: n = 8Different ways to break 8:• 8 = 1 + 7 → product = 1 × 7 = 7• 8 = 2 + 6 → product = 2 × 6 = 12• 8 = 3 + 5 → product = 3 × 5 = 15• 8 = 2 + 3 + 3 → product = 2 × 3 × 3 = 18 ✓ (Maximum!)Pattern Recognition:• Numbers 2 and 3 are optimal building blocks• 3 is better than larger numbers: 6 = 3+3 gives 9 > 6• When remainder is 1, use two 2s instead: 4 = 2+2 gives 4 > 3+1 = 3332= 18Optimal: Use as many 3s as possible!Mathematical insight: 3 maximizes product per unit sum
Understanding the Visualization
1
Try different splits
For n=8, try: 1+7=7, 2+6=12, 3+5=15, 4+4=16
2
Consider more splits
Try: 2+2+4=16, 2+3+3=18, 3+3+2=18
3
Find the pattern
Notice that using more 3s tends to give better results
4
Apply mathematical insight
3 is the magic number - use as many as possible!
Key Takeaway
🎯 Key Insight: The number 3 provides the optimal balance - it maximizes the product-to-sum ratio, making it the ideal building block for achieving maximum product.
Asked in
Amazon 15 Google 12 Microsoft 8 Meta 6
89.0K Views
Medium Frequency
~15 min Avg. Time
2.8K 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