data-structures · intermediate · ~15 min
Maximize the product of parts that sum to n.
Implement:
int integer_break(int n);
Break n (n >= 2) into a sum of at least two positive integers and return the maximum product of those parts.
n >= 2.
Maximum product.
At least two parts.
#include <stddef.h>
/* Break n (n>=2) into a sum of at least two positive integers; return the maximum product of those parts. */
int integer_break(int n){ (void)n; return 0; }
Forgetting a factor may itself be left unbroken — compare max(j, dp[j]).
n=2 -> 1 (1+1); n=4 -> 4 (2+2).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.