Practice Perfect Squares
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given an integer n, return the least number of perfect square numbers that sum to n. A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 1, 4, 9, and 16 are perfect squares while 3 and 11 are not.
Source: Perfect Squares on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
n = 12
Output
3
# Example 2
Input
n = 13
Output
2
Constraints
1 <= n <= 10^4
Related LeetCode Problems
Practice more problems similar to Perfect Squares.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.