Area of the largest rectangle possible from given coordinates | Java program for the above approach ; 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 ; Driver Code ; Given point ; Given length ; Given points ; Given length ; Function Call
import java . util . * ; class GFG { static int largestArea ( int arr1 [ ] , int n , int arr2 [ ] , int m ) { int end = 0 , start = 0 , i = 0 , j = 0 ; Arrays . sort ( arr1 ) ; Arrays . sort ( arr1 ) ; 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 ) ; } public static void main ( String args [ ] ) { int arr1 [ ] = { 1 , 2 , 4 } ; int N = arr1 . length ; int arr2 [ ] = { 1 , 3 , 4 } ; int M = arr2 . length ; System . out . println ( largestArea ( arr1 , N , arr2 , M ) ) ; } }