• + 0 comments

    Passed all but one test case:

    // 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";
    
        }  
    }