Skip to content
Onsite

Square Root of an Integer

EasyP2Coding

Given a non-negative integer n, return the integer square root of n: the largest integer x such that x * x <= n. Do not use a built-in square root or exponent function.

Example 1

Input
n = 16
Output
4

Example 2

Input
n = 8
Output
2
Why
2 * 2 = 4 <= 8 and 3 * 3 = 9 > 8.

Example 3

Input
n = 0
Output
0

Constraints

  • 0 <= n <= 10^12

Hints

Run checks the 3 visible tests, Submit all 13.