Sort by

recency

|

75 Discussions

|

  • + 0 comments

    My Python3 version

    def solve(coordinates):
        X, Y = zip(*coordinates)
        max_X, min_X = max(X), min(X)
        max_Y, min_Y = max(Y), min(Y)
        absminX, absminY = abs(min_X), abs(min_Y)
        rangeX = max_X - min_X
        rangeY = max_Y - min_Y
        max_range = max(rangeX, rangeY)
        if max_range > max([absminX, max_X, max_Y, absminY]):
            return float('{0:.12f}'.format(max_range))
        distance = (max(max_X, absminX)**2 + max(max_Y, absminY)**2) ** 0.5
        return float('{0:.12f}'.format(distance))
    
  • + 0 comments

    Can someone explain where i was wrong, i failed 17 cases

    public static double solve(List<List<Integer>> coordinates) {
        // Write your code here
            int maxX, minX, maxY, minY;
            maxX = maxY = Integer.MIN_VALUE;
            minX = minY = Integer.MAX_VALUE;
            for(List<Integer> co : coordinates){
                maxX = Math.max(co.get(0), maxX);
                minX = Math.min(co.get(0), minX);
                maxY = Math.max(co.get(1), maxY);
                minY = Math.min(co.get(1), minY);
                // if(co.get(0) == 0){
                //     if(co.get(1) > maxY) maxY = co.get(1);
                //     else if(co.get(1) < minY) minY = co.get(1);
                // } else {
                //     if(co.get(0) > maxX) maxX = co.get(0);
                //     else if(co.get(0) < minX) minX = co.get(0);
                // }
            }
            
            double longest = maxX - minX;
            if(longest < maxY - minY) longest = maxY - minY;
            double temp;
            temp = Math.sqrt(maxX*maxX + minY*minY);
            if(longest < temp) longest = temp;
            temp = Math.sqrt(maxX*maxX + maxY*maxY);
            if(longest < temp) longest = temp;
            temp = Math.sqrt(minX*minX + minY*minY);
            if(longest < temp) longest = temp;
            temp = Math.sqrt(minX*minX + maxY*maxY);
            if(longest < temp) longest = temp;
            return longest;
            
            // int maxAbsX, maxAbsY;
            // if(maxX >= 0 && minX >= 0){
            //     maxAbsX = maxX;
            // } else if(maxX <= 0){
            //     maxAbsX = -minX;
            // } else{
            //     if(maxX > -minX) maxAbsX = maxX;
            //     else maxAbsX = - minX;
            // }
            // if(maxY >= 0 && minY >= 0){
            //     maxAbsY = maxY;
            // } else if(maxY <= 0){
            //     maxAbsY = -minY;
            // } else {
            //     if(maxY > -minY) maxAbsY = maxY;
            //     else maxAbsY = - minY;   
            // }
            
            // double distXY = Math.sqrt(maxAbsX*maxAbsX + maxAbsY * maxAbsY);
            // return Math.max(Math.max(distX, distY), distXY);
        }
    
  • + 0 comments

    Can someone explain where i am wrong, i fail 17 cases

    public static double solve(List<List<Integer>> coordinates) {
        // Write your code here
            int maxX, minX, maxY, minY;
            maxX = maxY = Integer.MIN_VALUE;
            minX = minY = Integer.MAX_VALUE;
            for(List<Integer> co : coordinates){
                maxX = Math.max(co.get(0), maxX);
                minX = Math.min(co.get(0), minX);
                maxY = Math.max(co.get(1), maxY);
                minY = Math.min(co.get(1), minY);
                // if(co.get(0) == 0){
                //     if(co.get(1) > maxY) maxY = co.get(1);
                //     else if(co.get(1) < minY) minY = co.get(1);
                // } else {
                //     if(co.get(0) > maxX) maxX = co.get(0);
                //     else if(co.get(0) < minX) minX = co.get(0);
                // }
            }
            
            double longest = maxX - minX;
            if(longest < maxY - minY) longest = maxY - minY;
            double temp;
            temp = Math.sqrt(maxX*maxX + minY*minY);
            if(longest < temp) longest = temp;
            temp = Math.sqrt(maxX*maxX + maxY*maxY);
            if(longest < temp) longest = temp;
            temp = Math.sqrt(minX*minX + minY*minY);
            if(longest < temp) longest = temp;
            temp = Math.sqrt(minX*minX + maxY*maxY);
            if(longest < temp) longest = temp;
            return longest;
            
            // int maxAbsX, maxAbsY;
            // if(maxX >= 0 && minX >= 0){
            //     maxAbsX = maxX;
            // } else if(maxX <= 0){
            //     maxAbsX = -minX;
            // } else{
            //     if(maxX > -minX) maxAbsX = maxX;
            //     else maxAbsX = - minX;
            // }
            // if(maxY >= 0 && minY >= 0){
            //     maxAbsY = maxY;
            // } else if(maxY <= 0){
            //     maxAbsY = -minY;
            // } else {
            //     if(maxY > -minY) maxAbsY = maxY;
            //     else maxAbsY = - minY;   
            // }
            
            // double distXY = Math.sqrt(maxAbsX*maxAbsX + maxAbsY * maxAbsY);
            // return Math.max(Math.max(distX, distY), distXY);
        }
    
  • + 0 comments
    def solve(coordinates):
        x = sorted([x for x,y in coordinates if x != 0])
        y = sorted([y for x,y in coordinates if y != 0])
        max_distance_x_values = max(x)-min(x)
        max_distance_y_values = max(y)-min(y)
        y0 = 0
        if abs(x[0])>abs(x[-1]):
            x0 = abs(x[0])
        else:
            x0 = abs(x[-1])
        if abs(y[0])>abs(x[-1]):
            y0 = abs(y[0])
        else:
            y0 = abs(y[-1])
        hyp = math.sqrt(x0**2+y0**2)
        possible_answers = [hyp, max_distance_x_values, max_distance_y_values]
        return float('{0:.12f}'.format(max(possible_answers)))
    
  • + 0 comments

    For people using c++, change the output line to: fout << std::setprecision (18) << result << "\n";

    otherwise, the default precision does not meet the criteria in many of the test cases.