Valid Perfect Square - Problem
Given a positive integer num, return true if num is a perfect square or false otherwise.
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.
You must not use any built-in library function, such as sqrt.
Input & Output
Example 1 — Perfect Square
$
Input:
num = 16
›
Output:
true
💡 Note:
16 is a perfect square because 4 * 4 = 16
Example 2 — Not Perfect Square
$
Input:
num = 14
›
Output:
false
💡 Note:
14 is not a perfect square. √14 ≈ 3.74, which is not an integer
Example 3 — Edge Case
$
Input:
num = 1
›
Output:
true
💡 Note:
1 is a perfect square because 1 * 1 = 1
Constraints
- 1 ≤ num ≤ 231 - 1
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given positive integer num
2
Process
Find if there exists integer k where k² = num
3
Output
Return true if perfect square, false otherwise
Key Takeaway
🎯 Key Insight: Use binary search to efficiently find the integer square root in O(log n) time
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code