Maximum Manhattan distance between a distinct pair from N coordinates | C # program for the above approach ; Pair class ; 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
using System ; using System . Collections . Generic ; class GFG { public class Pair { public int x ; public int y ; public Pair ( int x , int y ) { this . x = x ; this . y = y ; } } static void MaxDist ( List < Pair > A , int N ) { int maximum = int . MinValue ; for ( int i = 0 ; i < N ; i ++ ) { int sum = 0 ; for ( int j = i + 1 ; j < N ; j ++ ) { sum = Math . Abs ( A [ i ] . x - A [ j ] . x ) + Math . Abs ( A [ i ] . y - A [ j ] . y ) ; maximum = Math . Max ( maximum , sum ) ; } } Console . WriteLine ( maximum ) ; } public static void Main ( String [ ] args ) { int n = 3 ; List < Pair > al = new List < Pair > ( ) ; Pair p1 = new Pair ( 1 , 2 ) ; al . Add ( p1 ) ; Pair p2 = new Pair ( 2 , 3 ) ; al . Add ( p2 ) ; Pair p3 = new Pair ( 3 , 4 ) ; al . Add ( p3 ) ; MaxDist ( al , n ) ; } }