Problem
Return the least number of perfect squares (1, 4, 9, 16, ...) that sum to n. You may use the same square more than once.
Example 1
- Input
- n = 12
- Output
- 3
- Why
- 4 + 4 + 4
Example 2
- Input
- n = 13
- Output
- 2
- Why
- 4 + 9
Example 3
- Input
- n = 7
- Output
- 4
- Why
- 4 + 1 + 1 + 1
Constraints
1 <= n <= 10^4