 All Problems
Sqrt(x)
easy
binary search
math
amazon
google
apple
microsoft

Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well.

You must not use any built-in exponent function or operator.

Example 1:

Input: 4
Output: 2

Example 2:

Input: 8
Output: 2
(Since sqrt(8) ≈ 2.82, rounded down is 2)

Input format: Single integer x.

Output format: Floor of sqrt(x).

Run to check your code against the sample cases, or submit to run every case