Whole Square Root
Given a whole number x, return its whole square root: the largest whole number r with r × r ≤ x. In other words, the square root of x with everything after the decimal point dropped.
Do not use a built-in square root or power function: the point is to find r yourself.
Examples
x = 16 → 4
x = 20 → 4
x = 0 → 0
x = 1 → 14 × 4 = 16 is at most 20, and 5 × 5 = 25 is not, so the whole square root of 20 is 4.
Constraints
xis between 0 and 10,000,000,000.- Aim for O(log x): trying 0, 1, 2, … in turn takes about √x steps.
Console
›Run to see what your code prints
Run checks the 4 visible cases here, in your browser. Submit runs all 9 on the judge, 5 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.