Given the integer n, split it into the sum of at least two positive integers. The parts may be equal, and their order does not affect the result. The product of a split is the multiplication of all its parts.
Implement Solution.integerBreak, which receives n and determines the greatest product obtainable from any valid split.
Return that maximum product as a JSON integer.
Example 1:
Input: n = 4
Output: 4
Explanation: The best split is 2 + 2, whose product is 4; splitting into 1 + 3 produces only 3.
Example 2:
Input: n = 6
Output: 9
Explanation: The split 3 + 3 gives product 9, which is larger than the products from the other valid splits.
Example 3:
Input: n = 11
Output: 54
Explanation: The split 3 + 3 + 3 + 2 sums to 11 and has product 54, the greatest possible product.
Constraints:
2 <= n <= 58 is an integer.Every part used in a split must be a positive integer.A valid split contains at least two parts whose sum is exactly n.The maximum product fits in a 32-bit signed integer.Need help or want more practice?