Problem title
Difficulty
Avg time to solve

Jumping Numbers
Moderate
15 mins
Implement a Queue
Easy
20 mins
Merge Two Sorted Linked Lists
Moderate
15 mins
Tower of Hanoi
Easy
15 mins
Implementation: HashMap
Easy
30 mins
Longest Consecutive Sequence
Moderate
40 mins
Total Salary
Easy
10 mins
Square Root
Easy
15 mins
Middle Of Linked List
Easy
20 mins
Minimum Jumps
Moderate
25 mins
61

Square Root

Difficulty: EASY
Avg. time to solve
15 min
Success Rate
80%

Problem Statement

You are given a positive integer ‘N’. Your task is to find and return its square root. If ‘N’ is not a perfect square, then return the floor value of sqrt(N).

For example:

For ‘N’  = 25, return 5 , for ‘N’ = 20 return 4, for ‘N’ = 2 return 1.
Input Format:
The first line of input contains an integer ‘T’, denoting the number of test cases. Then each test case follows.

The first and the only line of each test case contains the Integer ‘N’.
Output Format:
For each test case, print a single line containing an integer denoting the square root of ‘N’.

The output of each test case will be printed on a separate line.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 5
0 <= N <= 10 ^ 16

Time Limit: 1 sec.
Sample Input 1:
2
4
6
Sample Output 1:
2
2
Explanation of Sample Input 1:
In the first test case, the square root of the given number 4 is 2.

In the second test case, the square root of the given number 6 lies between 2 and 3, so the floor value is 2.
Sample Input 2:
2
10
100
Sample Output 2:
3
10
Explanation of Sample Output 2:
In the first test case, the square root of the given number 10 lies between 3 and 4, so the floor value is 3.

In the second test case, the square root of the given number 100 is 10.
Reset Code
Full screen
copy-code
Console