Square Root of Integer

Let's try to solve one problem with different inputs. Difficulty Level: Easy

Problem statement

Suppose we are given an integer a. Compute and return the square root of a. If a is not a perfect square, we will truncate the decimal digits.

Constraints:

  • 0a1030 \leq a \leq 10^3

Example 1:

Input: 11    
Output: 3    

Explanation: The square root of 11 is 3.3166... and since the decimal part is truncated, 3 is returned.

Example 2:

Input: 9    
Output: 3    

Explanation: 9 gives a perfect square root.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.