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 ; Lists to store maximum and minimum of all the four forms ; Sorting both the Lists ; Driver Code ; Given Co - ordinates ; Function call
using System ; using System . Collections . Generic ; class GFG { 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 ) { List < int > V = new List < int > ( ) ; List < int > V1 = new List < int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { V . Add ( A [ i ] . x + A [ i ] . y ) ; V1 . Add ( A [ i ] . x - A [ i ] . y ) ; } V . Sort ( ) ; V1 . Sort ( ) ; int maximum = Math . Max ( ( V [ V . Count - 1 ] - V [ 0 ] ) , ( V1 [ V1 . Count - 1 ] - V1 [ 0 ] ) ) ; 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 ) ; } }