Tap here to switch tabs
Problem
Ask
Submissions

Problem: Sqrt(x)

med
30 min
Understand how to implement a modified binary search algorithm to compute the square root of a non-negative integer rounded down. This lesson helps you develop problem-solving skills for coding interviews by tackling constraints that prohibit using built-in exponentiation functions.

Statement

Given a non-negative integer x, compute and return the square root of x rounded down to the nearest integer. The result must also be non-negative.

Built-in exponent functions or operators (e.g., pow(x, 0.5) in C++ or x ** 0.5 in Python) are not permitted.

Constraints:

  • 00 \leq x 2311\leq 2^{31} - 1

Tap here to switch tabs
Problem
Ask
Submissions

Problem: Sqrt(x)

med
30 min
Understand how to implement a modified binary search algorithm to compute the square root of a non-negative integer rounded down. This lesson helps you develop problem-solving skills for coding interviews by tackling constraints that prohibit using built-in exponentiation functions.

Statement

Given a non-negative integer x, compute and return the square root of x rounded down to the nearest integer. The result must also be non-negative.

Built-in exponent functions or operators (e.g., pow(x, 0.5) in C++ or x ** 0.5 in Python) are not permitted.

Constraints:

  • 00 \leq x 2311\leq 2^{31} - 1