Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

62. Sqrt(x)

EasyDay 18 of 60Binary Search

Given a non-negative integer x, return the square root of x rounded down to the nearest integer. You may not use any built-in power or square root function such as pow(x, 0.5) or sqrt.

Example 1
Input: x = 4
Output: 2
Example 2
Input: x = 8
Output: 2
The real root is 2.828..., which rounds down to 2.
Constraints
  • 0 <= x <= 2^31 - 1
Hints
Frequently asked at: Amazon, Microsoft, Apple, Bloomberg
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min