Find minimum area of rectangle with given set of coordinates | # function to find minimum area of Rectangle ; creating empty columns ; fill columns with coordinates ; Driver code
function minAreaRect ( points ) { let columns = new Set ( ) ; for ( let point = 0 ; point < points . length ; point ++ ) columns . add ( 40001 * points [ point ] [ 0 ] + points [ point ] [ 1 ] ) ; let ans = Number . MAX_VALUE ; for ( let i = 0 ; i < points . length ; ++ i ) for ( let j = i + 1 ; j < points . length ; ++ j ) { if ( points [ i ] [ 0 ] != points [ j ] [ 0 ] && points [ i ] [ 1 ] != points [ j ] [ 1 ] ) { if ( columns . has ( 40001 * points [ i ] [ 0 ] + points [ j ] [ 1 ] ) && columns . has ( 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 < Number . MAX_VALUE ? ans : 0 ; } let A = [ [ 1 , 1 ] , [ 1 , 3 ] , [ 3 , 1 ] , [ 3 , 3 ] , [ 2 , 2 ] ] ; document . write ( minAreaRect ( A ) ) ;