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 points ; Initialize two arrays ; Store x and y coordinates ; Sort arrays ; Initialize max differences ; Find max adjacent differences ; Return answer ; Driver Code ; Given points ; Total points ; Function call
def maxRectangle ( sequence , size ) : NEW_LINE INDENT X_Cord = [ 0 ] * size NEW_LINE Y_Cord = [ 0 ] * size NEW_LINE for i in range ( size ) : NEW_LINE INDENT X_Cord [ i ] = sequence [ i ] [ 0 ] NEW_LINE Y_Cord [ i ] = sequence [ i ] [ 1 ] NEW_LINE DEDENT X_Cord . sort ( ) NEW_LINE Y_Cord . sort ( ) NEW_LINE X_Max = 0 NEW_LINE Y_Max = 0 NEW_LINE for i in range ( size - 1 ) : NEW_LINE INDENT X_Max = max ( X_Max , X_Cord [ i + 1 ] - X_Cord [ i ] ) NEW_LINE Y_Max = max ( Y_Max , Y_Cord [ i + 1 ] - Y_Cord [ i ] ) NEW_LINE DEDENT return X_Max * Y_Max NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT point = [ [ - 2 , 0 ] , [ 2 , 0 ] , [ 4 , 0 ] , [ 4 , 2 ] ] NEW_LINE n = len ( point ) NEW_LINE print ( maxRectangle ( point , n ) ) NEW_LINE DEDENT