Description

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.

Examples

Input:x = 4
Output:2
Explanation:

Since 2 * 2 = 4 exactly, the integer square root is 2 with no rounding needed.

Input:x = 8
Output:2
Explanation:

The square root of 8 is 2.82842..., rounded down to 2.

Input:x = 1
Output:1
Explanation:

Since 1 * 1 = 1 exactly, the integer square root is 1. This is a base case where the number equals its own square root.

Input:x = 0
Output:0
Explanation:

Zero is a special case: 0 * 0 = 0, so the integer square root of 0 is trivially 0.

Constraints

  • 0 ≤ x ≤ 2³¹ - 1

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!