We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

// Complete the solve function below.
static String solve(int d, int k) {
//get integer format of radius
int r = (int)Math.sqrt(d);
int count = 0;
//loop for all integer values on X axis
for(int i = -r; i<r; i++){
//calculate the float/double value of Y
// Let's say, it could be 2.0 or 2.3
double y = Math.sqrt(d - i*i);
// convert to INT so it will become either 2.0 in above cases
int intY = (int)y;
//now compare the int version with original version.
//if they are same, then Y is also integer and hence we got our point on
//the circle. Count is incremented by 2 because, this new point is applicable both above and below x axis.
if((float)intY == y ){
count+=2;
}
}
if(k >= count){
return "possible";
} else {
return "impossible";
}
}

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website

## Circle City

You are viewing a single comment's thread. Return to all comments â†’

Passed all but one test case: