Area of the largest rectangle possible from given coordinates | Function to find the maximum possible area of a rectangle ; Initialize variables ; Sort array arr1 [ ] ; Sort array arr2 [ ] ; Traverse arr1 [ ] and arr2 [ ] ; If arr1 [ i ] is same as arr2 [ j ] ; If no starting point is found yet ; Update maximum end ; If arr [ i ] > arr2 [ j ] ; If no rectangle is found ; Return the area ; Given point ; Given length ; Given points ; Given length ; Function Call
function largestArea ( arr1 , n , arr2 , m ) { var end = 0 , start = 0 , i = 0 , j = 0 ; arr1 . sort ( ) ; arr2 . sort ( ) ; while ( i < n && j < m ) { if ( arr1 [ i ] == arr2 [ j ] ) { if ( start == 0 ) start = arr1 [ i ] ; else end = arr1 [ i ] ; i ++ ; j ++ ; } else if ( arr1 [ i ] > arr2 [ j ] ) j ++ ; else i ++ ; } if ( end == 0 start == 0 ) return 0 ; else return ( end - start ) ; } var arr1 = [ 1 , 2 , 4 ] ; var N = arr1 . length ; var arr2 = [ 1 , 3 , 4 ] ; var M = arr2 . length ; document . write ( largestArea ( arr1 , N , arr2 , M ) ) ;