Maximum Manhattan distance between a distinct pair from N coordinates | Python3 program for the above approach ; Function to calculate the maximum Manhattan distance ; Stores the maximum distance ; Find Manhattan distance using the formula | x1 - x2 | + | y1 - y2 | ; Updating the maximum ; Driver code ; Given co - ordinates ; Function call
import sys NEW_LINE def MaxDist ( A , N ) : NEW_LINE INDENT maximum = - sys . maxsize NEW_LINE for i in range ( N ) : NEW_LINE INDENT sum = 0 NEW_LINE for j in range ( i + 1 , N ) : NEW_LINE INDENT Sum = ( abs ( A [ i ] [ 0 ] - A [ j ] [ 0 ] ) + abs ( A [ i ] [ 1 ] - A [ j ] [ 1 ] ) ) NEW_LINE maximum = max ( maximum , Sum ) NEW_LINE DEDENT DEDENT print ( maximum ) NEW_LINE DEDENT N = 3 NEW_LINE A = [ [ 1 , 2 ] , [ 2 , 3 ] , [ 3 , 4 ] ] NEW_LINE MaxDist ( A , N ) NEW_LINE