total. Write it as a sum of perfect squares (1, 4, 9, 16, …) using as few terms as possible. Any square may be used any number of times.
Return the smallest possible number of terms.total=18 → 2
18 = 9 + 9. One square is not enough, since 18 itself is not a square.
total=7 → 4
7 = 4 + 1 + 1 + 1; no shorter sum exists.
total=49 → 1
49 = 7², so a single term is enough.
total=18
2
Run checks the first 3 tests in your browser. Submit checks all 77 tests on the server, hidden ones included.