Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Sqrt(x)

Easy
binary-searchmath

Given a non-negative integer x, return the integer square root of x — the largest integer r such that r² ≤ x. Do not use built-in exponent/sqrt functions.

Input: one line, the integer x. Output: the integer square root.

Example 1
Input:
4
Output:
2
Example 2
Input:
8
Output:
2

√8 ≈ 2.83, truncated to 2.

Constraints

  • 0 ≤ x ≤ 2^31 − 1
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.