/69. Integer Square Root

69. Integer Square Root

Easy
Probability41.5% acceptance

Given a non-negative integer input_value, compute and return the largest integer result_value such that result_value * result_value <= input_value. Do not use any built-in exponentiation functions or operators (e.g., pow, **, sqrt).

Example 1

Input: input_value=15

Output: 3

Explanation: The square root of 15 is approximately 3.872, so the largest integer less than or equal to the square root is 3.

Example 2

Input: input_value=27

Output: 5

Explanation: The square root of 27 is approximately 5.196, so the largest integer less than or equal to the square root is 5.

Example 3

Input: input_value=0

Output: 0

Explanation: The square root of 0 is 0.

Constraints

  • 0 <= input_value <= 231 - 1
  • No built-in exponentiation or square root functions/operators may be used
Python (current runtime)

Case 1

Input: input_value=49

Expected: 7

Case 2

Input: input_value=123

Expected: 11

Case 3

Input: input_value=1

Expected: 1

Case 4

Input: input_value=999

Expected: 31

Case 5

Input: input_value=10000

Expected: 100