Minimum length of square to contain at least half of the given Coordinates | 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
function mod ( x ) { if ( x >= 0 ) return x ; return - x ; } function findSquare ( n ) { let points = [ [ 1 , 2 ] , [ - 3 , 4 ] , [ 1 , 78 ] , [ - 3 , - 7 ] ] ; let a = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { let x , y ; x = points [ i ] [ 0 ] ; y = points [ i ] [ 1 ] ; a [ i ] = Math . max ( mod ( x ) , mod ( y ) ) ; } a . sort ( function ( a , b ) { return a - b } ) ; let index = ( Math . floor ( n / 2 ) - 1 ) ; document . write ( " " + a [ index ] ) ; } let N ; N = 4 ; findSquare ( N ) ;