Skip to interview prep
Apexed

30. Integer Square Root (Binary Search)

EasySearching

Return the floor of the square root of a non-negative integer x, without using a built-in square root or power function.

Example 1

Input: x = 8
Output: 2

Example 2

Input: x = 16
Output: 4

Constraints

  • 0 ≤ x ≤ 2³¹ − 1

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 5 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Integer Square Root (Binary Search) — coding interview practice — Apexed