/343. Integer Break

343. Integer Break

Medium
Probability62% acceptance

Given a positive integer total_value, partition it into the sum of at least two positive integers. Find the maximum possible product of these integers. Return the maximum product as an integer.

Example 1

Input: total_value=5

Output: 6

Explanation: 5 = 2 + 3, 2*3 = 6

Example 2

Input: total_value=8

Output: 18

Explanation: 8 = 3 + 3 + 2, 3*3*2 = 18

Example 3

Input: total_value=12

Output: 81

Explanation: 12 = 3 + 3 + 3 + 3, 3*3*3*3 = 81

Constraints

  • 2 <= total_value <= 58
  • total_value is a positive integer
Python (current runtime)

Case 1

Input: total_value=6

Expected: 9

Case 2

Input: total_value=9

Expected: 27

Case 3

Input: total_value=15

Expected: 243