Math Fundamentals18 sections · 814 units
Open in Course

Valid Perfect Square - The Equation

What you're checking

You need to find if there exists an integer kk such that k2=numk^2 = num. This is a quadratic equation.

One approach: compute num\sqrt{num} and check if it's an integer. But floating point can be imprecise.

Better approach: use binary search to find kk in the range [1,num][1, num]. If k2=numk^2 = num exactly, return true.