• + 0 comments

    My code fails for the last 7 cases. Any reason why?

        a = b = 0
        for i in range(len(coordinates)):
            coordinates[i][0] = float(coordinates[i][0])
            coordinates[i][1] = float(coordinates[i][1])
            a+=coordinates[i][0]
            b+=coordinates[i][1]
        a = a/len(coordinates)
        b = b/len(coordinates)
        f = float('inf')
        mp = [0,0]
        for i in range(len(coordinates)):
            if math.sqrt((a-coordinates[i][0])**2+(b-coordinates[i][1])**2)<f:
                f = math.sqrt((a-coordinates[i][0])**2+(b-coordinates[i][1])**2)
                mp = coordinates[i]
        mindist=0
        for i in range(len(coordinates)):
            mindist +=  max(abs(mp[0]-coordinates[i][0]),abs(mp[1]-coordinates[i][1]))
                
        return(int(mindist))