279. Perfect Squares

Practice Perfect Squares for free on NudgeCode: Medium, Dynamic Programming pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Return the smallest number of perfect squares (1, 4, 9, 16, ...) that add up to n. A square may be used more than once.

Example

n = 12  ->  3   (4 + 4 + 4)
n = 13  ->  2   (4 + 9)

Constraints