Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com

Square Root Of An Integer

Easy
0/40
Average time to solve is 20m
profile
Contributed by
40 upvotes
Asked in companies
GoogleTata 1mgOracle

Problem statement

You are given an integer ‘A’. Your task is to find the greatest non-negative integer whose square is less than or equal to ‘A’.

Square of a number is the product of the number with itself. For e.g. square of 3 is 9.

Detailed explanation ( Input/output format, Notes, Images )
Sample Input 1
2
8
9
Sample Output 1
2
3
Explanation Of Input 1
The greatest non-negative integer for test case 1 whose square is less than equal to 8 is 2 as the square of 3 is 9 which is greater than 8.

The greatest non-negative integer for test case 2 whose square is less than equal to 9 is 3 as the square of 4 is 16 which is greater than 9. 
Sample Input 2
2
1
0
Sample Output 2
1
0
Constraints
1 <= T <= 10^4
0 <= A <= 10^5

Time Limit: 1 sec
Expected Time Complexity:
Time Complexity : O(log(n))
Space Complexity : O(1)
Full screen
Console