Given a positive integer, decide whether it is a perfect square, meaning it equals some whole number multiplied by itself. Return true when such a whole number exists and false otherwise.
The catch is that built-in square-root helpers are not allowed, so you must determine the answer using arithmetic and a search of your own.
Example 1
Input: num = 16
Output: true
16 is 4 times 4, so it is a perfect square.
Example 2
Input: num = 14
Output: false
No whole number squared gives 14, so the answer is false.
Constraints
1 ≤ num ≤ 2^31 - 1You may not use any built-in square root functionSee the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI