dsa · easy
Integer Square Root
Given a non-negative integer x, return the integer square root: the greatest integer r such that r * r <= x. Do not use a built-in exponent that returns a float and then truncates blindly if that would overflow the true floor.
Arguments
x— non-negative integer whose floor square root you return
Example
x = 8 → 2 because 2*2 = 4 <= 8 and 3*3 = 9 > 8.
x = 4 → 2.
Constraints
0 <= x <= 2^31 - 1
Examples
Example 1
Input: 4 Expected: 2
Example 2
Input: 8 Expected: 2