Find minimum area of rectangle with given set of coordinates | package whatever Java Implementation of above approach ; # function to find minimum area of Rectangle ; creating empty columns ; fill columns with coordinates ; Driver code
import java . io . * ; import java . util . * ; class GFG { public static int minAreaRect ( int [ ] [ ] points ) { @ SuppressWarnings ( " unchecked " ) Set < Integer > columns = new HashSet ( ) ; for ( int [ ] point : points ) columns . add ( 40001 * point [ 0 ] + point [ 1 ] ) ; int ans = Integer . MAX_VALUE ; for ( int i = 0 ; i < points . length ; ++ i ) for ( int j = i + 1 ; j < points . length ; ++ j ) { if ( points [ i ] [ 0 ] != points [ j ] [ 0 ] && points [ i ] [ 1 ] != points [ j ] [ 1 ] ) { if ( columns . contains ( 40001 * points [ i ] [ 0 ] + points [ j ] [ 1 ] ) && columns . contains ( 40001 * points [ j ] [ 0 ] + points [ i ] [ 1 ] ) ) { ans = Math . min ( ans , Math . abs ( points [ j ] [ 0 ] - points [ i ] [ 0 ] ) * Math . abs ( points [ j ] [ 1 ] - points [ i ] [ 1 ] ) ) ; } } } return ans < Integer . MAX_VALUE ? ans : 0 ; } public static void main ( String [ ] args ) { int [ ] [ ] A = { { 1 , 1 } , { 1 , 3 } , { 3 , 1 } , { 3 , 3 } , { 2 , 2 } } ; System . out . println ( minAreaRect ( A ) ) ; } }