Minimum length of square to contain at least half of the given Coordinates | Java 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
import java . util . * ; class GFG { static int mod ( int x ) { if ( x >= 0 ) return x ; return - x ; } static void findSquare ( int n ) { int points [ ] [ ] = { { 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 ) ) ; } Arrays . sort ( a ) ; int index = ( int ) ( Math . floor ( n / 2 ) - 1 ) ; System . out . println ( " Minimum ▁ M ▁ required ▁ is : ▁ " + a [ index ] ) ; } public static void main ( String [ ] args ) { int N ; N = 4 ; findSquare ( N ) ; } }