Back to Practice Dashboard
Python BasicsEasy
Perfect Square
Learn how to solve the 'Perfect Square' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
Easy
Write a function is_perfect_square(n) that takes a non-negative integer n and returns True if n is a perfect square, or False otherwise. A perfect square is an integer that is the square of some integer (e.g., 0, 1, 4, 9, 16, ...).
Constraints
- •0 <= n <= 10^9
Examples
Example 1
Input
n = 16
Output
True
Explanation
16 = 4 × 4, so it is a perfect square.
Example 2
Input
n = 14
Output
False
Explanation
There is no integer whose square is 14.
Example 3
Input
n = 0
Output
True
Explanation
0 = 0 × 0, so it is a perfect square.
Need a Hint?
Use simple arithmetic operators (like modulo `%`, division `//`), conditional checks, or loops to inspect number properties.
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.