Fewest Perfect Squares
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 1
n 12
returns 3
4 + 4 + 4.
Example 2
n 13
returns 2
4 + 9.
Constraints
1 <= n <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Dynamic programming problems
- Gems That ClashMedium
- Hands That Hit the TargetMedium
- Keystrokes to TransformMedium
- Knight on the KeypadMedium
- Letter DecodingsMedium
- Lightest Deletions to MatchMedium
- Longest Climbing ChainMedium
- Longest Insertion LadderMedium