Return the Floor of a Square Root

Quick Overview

Compute a nonnegative integer square root rounded downward without built-in exponentiation functions or operators.

Return the Floor of a Square Root

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem For the nonnegative integer `value`, return its square root rounded downward to an integer. The result must also be nonnegative. You must not use a built-in exponentiation function or an exponentiation operator to compute the answer. ### Examples **Example 1** ```text Input: value = 49 Output: 7 ``` This input is a perfect square: `7 * 7` equals `49`. **Example 2** ```text Input: value = 50 Output: 7 ``` The square root is greater than `7` but less than `8`, so rounding downward gives `7`. ### Constraints - `0 <= value <= 2^31 - 1`

Overview: Compute a nonnegative integer square root rounded downward without built-in exponentiation functions or operators.

Amazon logo
Amazon
Date not reported
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

For the nonnegative integer value, return its square root rounded downward to an integer. The result must also be nonnegative.

You must not use a built-in exponentiation function or an exponentiation operator to compute the answer.

Examples

Example 1

Input: value = 49
Output: 7

This input is a perfect square: 7 * 7 equals 49.

Example 2

Input: value = 50
Output: 7

The square root is greater than 7 but less than 8, so rounding downward gives 7.

Constraints

  • 0 <= value <= 2^31 - 1