Sqrt(x)

Given a non-negative integer x, return the integer square root of x, meaning the largest integer r such that r*r <= x. This is a classic boundary and overflow-safe arithmetic problem.

Input Format

x = non-negative integer

Output Format

floor square root of x

Constraints

  • 0 <= x <= 2^31 - 1

Examples

Example 1:

Input:

x = 4

Output:

2

Explanation:

The square root of 4 is exactly 2.

Example 2:

Input:

x = 8

Output:

2

Explanation:

The floor square root of 8 is 2 because 3*3 > 8.

Loading...
Sqrt(x) - Math DSA Problem