Perfect Squares
Given an integer n, return the least number of perfect square numbers (1, 4, 9, 16, ...) that sum to n. The same square may be used multiple times.
Open official problem prompt ↗Compute the minimum count of perfect squares whose sum is exactly n.
Making change for n using coins of denominations 1, 4, 9, 16, ... and using as few coins as possible.
- Input
- n = 12
- Output
- 3
- Why
- 12 = 4 + 4 + 4 uses three squares; no combination of two squares sums to 12.
1 <= n <= 10^4