/69. Sqrt(x)

69. Sqrt(x)

Easy
Probability41.5% acceptance

Given a non-negative integer input_value, return the largest integer result such that result * result <= input_value. Do not use any built-in exponentiation functions or operators.

Example 1

Input: input_value=15

Output: 3

Explanation: The square root of 15 is approximately 3.872, so the largest integer whose square is <= 15 is 3.

Example 2

Input: input_value=0

Output: 0

Explanation: The square root of 0 is 0.

Example 3

Input: input_value=27

Output: 5

Explanation: The square root of 27 is approximately 5.196, so the largest integer whose square is <= 27 is 5.

Constraints

  • 0 <= input_value <= 231 - 1
  • Do not use built-in exponentiation functions or operators
Python (current runtime)

Case 1

Input: input_value=1

Expected: 1

Case 2

Input: input_value=49

Expected: 7

Case 3

Input: input_value=100

Expected: 10

Case 4

Input: input_value=999

Expected: 31

Case 5

Input: input_value=123456789

Expected: 11111