A rope of integer length n must be cut into at least two pieces of positive integer length. The pieces are then sold for a price equal to the product of their lengths. Return the largest price obtainable.
Examples
Input: n = 13
Output: 108
Explanation: 3 + 3 + 3 + 4 = 13 and 3 * 3 * 3 * 4 = 108.
Input: n = 3
Output: 2
Explanation: the cut 1 + 2 is best; selling the rope whole for 3 is not allowed.
Constraints
- Target complexity: O(n^2) time (an O(n) or O(1) arithmetic solution is also fine).
Goals
- Maximise a product over all ways to split an integer
- Handle the requirement of at least two pieces separately from the recurrence