Minimum length of square to contain at least half of the given Coordinates | C # program to find next identical year ; Function to Calculate Absolute Value ; Function to Calculate the Minimum value of M ; To store the minimum M for each point in array ; Sort the array ; Index at which atleast required point are inside square of length 2 * M ; Driver Code
using System ; class GFG { static int mod ( int x ) { if ( x >= 0 ) return x ; return - x ; } static void findSquare ( int n ) { int [ , ] points = new int [ 4 , 2 ] { { 1 , 2 } , { - 3 , 4 } , { 1 , 78 } , { - 3 , - 7 } } ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int x , y ; x = points [ i , 0 ] ; y = points [ i , 1 ] ; a [ i ] = Math . Max ( mod ( x ) , mod ( y ) ) ; } Array . Sort ( a ) ; int index = ( int ) ( n / 2 - 1 ) ; Console . WriteLine ( " Minimum ▁ M ▁ required ▁ is : ▁ " + a [ index ] ) ; } public static void Main ( String [ ] args ) { int N ; N = 4 ; findSquare ( N ) ; } }