MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / mySqrt

Method mySqrt

CountSquares.java:4–21  ·  view source on GitHub ↗
(int N )

Source from the content-addressed store, hash-verified

2{
3 // return either a perfect square root or floor value
4 public static int mySqrt(int N ) {
5 int start=1;
6 int end=N;
7 while(start<=end)
8 {
9 int mid = start+(end-start)/2;
10 if(mid<=N/mid)
11 {
12 if(N%mid==0 && mid==N/mid)
13 {
14 return mid;
15 }
16 start=mid+1;
17 }
18 else end=mid-1;
19 }
20 return start;
21 }
22 static int countSquares(int N) {
23 // code here
24 int sqrRoot = mySqrt(N);

Callers 1

countSquaresMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected