Square Root (Integral)
Given a number N, find its square root. You need to find and print only the integral part of square root of N.
For eg. if number given is 18, answer is 4.
Input format :
Integer N
Output Format :
Square root of N (integer part only)
Constraints :
0 <= N <= 10^8
CodingNinjas
author
2y
Initially, I have told him a brute-force approach of O(n). He asked for optimization. Then I have given a binary search approach. He agreed to that and asked me to write code for that. I had written t...read more
CodingNinjas
author
2y
Space Complexity: Explanation: Time Complexity: Explanation:
Kamakshi Dhankar
2y
import java.util.Scanner ;
public class Main {
public static void main(String[] args) {
// Write your code here
int i = 1 , result =1 ;
Scanner s = new Scanner(System.in);
int N = s.nextInt();
while(result<=N) {
i++ ;
result = i*i ;
}
System.out.println( i- 1 );
}
}
Add answer anonymously...
Top Oracle Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Oracle Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app