Perfect Squares
MediumDynamic Programming
Decode it first. Clues, constraints, pattern and plan before any code.Return the least number of perfect squares (1, 4, 9, 16, ...) that sum to n. You may use the same square more than once.
n = 12 → 3 (4 + 4 + 4)
n = 13 → 2 (4 + 9)
n = 7 → 4 (4 + 1 + 1 + 1)Constraints
1 <= n <= 10^4