Area of the largest rectangle formed by lines parallel to X and Y axis from given set of points | Function to return the area of the largest rectangle formed by lines parallel to X and Y axis from given set of polets ; Initialize two arrays ; Store x and y coordinates ; Sort arrays ; Initialize max differences ; Find max adjacent differences ; Return answer ; Given points ; Total points ; Function call
function maxRectangle ( sequence , size ) { let X_Cord = [ ] ; let Y_Cord = [ ] ; for ( let i = 0 ; i < size ; i ++ ) { X_Cord [ i ] = sequence [ i ] [ 0 ] ; Y_Cord [ i ] = sequence [ i ] [ 1 ] ; } X_Cord . sort ( ) ; Y_Cord . sort ( ) ; let X_Max = 0 , Y_Max = 0 ; for ( let i = 0 ; i < size - 1 ; i ++ ) { X_Max = Math . max ( X_Max , X_Cord [ i + 1 ] - X_Cord [ i ] ) ; Y_Max = Math . max ( Y_Max , Y_Cord [ i + 1 ] - Y_Cord [ i ] ) ; } return X_Max * Y_Max ; } let point = [ [ - 2 , 0 ] , [ 2 , 0 ] , [ 4 , 0 ] , [ 4 , 2 ] ] ; let n = point . length ; document . write ( maxRectangle ( point , n ) ) ;