Overview
This problem asks us to find the optimal way to break down a number to maximize the product of its parts. It demonstrates overlapping subproblems perfectly.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Given an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers.
This problem asks us to find the optimal way to break down a number to maximize the product of its parts. It demonstrates overlapping subproblems perfectly.
To break `i`, we can try all possible first parts `j` (from 1 to `i-1`). The second part is `i-j`.
For the second part `i-j`, we have a choice: we can leave it as is, or we can break it down further. That's why we compare `j * (i-j)` with `j * dp[i-j]`.
Fun fact: breaking a number into 3s maximizes the product. A greedy math approach runs in O(1) time, but this DP solution runs in O(N^2).