Sqrt x Problem
Sqrt x Problem — ExecCode School DSA Practice
Solve the Sqrt x problem on ExecCode. Free online school DSA practice in Math. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well. You must not use any built-in exponent function or operator, such as pow(x, 0.5) or x to the power 0.5, and must instead binary search the answer directly.
Examples
Input x = 8; Output 2. Input x = 4; Output 2. Input x = 0; Output 0
Constraints
0 ≤ x ≤ 2³¹ - 1
Practice Sqrt x free on ExecCode. Browse DSA problems, topic map, and placement guides.