Given an integer n, return the least number of perfect square numbers (1, 4, 9, 16, ...) that sum to n.
DP: dp[i] = minimum number of perfect squares summing to i. For each i, try all perfect squares <= i.
- Initialize dp[] with i (worst case: all 1s).
- For each i from 1 to n: for each j where j*j <= i: dp[i] = min(dp[i], dp[i-j*j]+1).
- Return dp[n].
- Time Complexity: O(N * sqrt(N))
- Space Complexity: O(N)