text: Largest area possible after removal of a series of horizontal & vertical bars | Function to find the largest area when a series of horizontal & vertical bars are removed ; Stores all bars ; Insert horizontal bars ; Insert vertictal bars ; Remove horizontal separators from s1 ; Remove vertical separators from s2 ; Stores left out horizontal and vertical separators ; Sort both list in ascending order ; Find maximum difference of neighbors of list1 ; Find max difference of neighbors of list2 ; Print largest volume ; Given value of N & M ; Given arrays ; Function call to find the largest area when a series of horizontal & vertical bars are removed
code: function largestArea ( N , M , H , V , h , v ) { var s1 = new Set ( ) ; var s2 = new Set ( ) ; for ( var i = 1 ; i <= N + 1 ; i ++ ) s1 . add ( i ) ; for ( var i = 1 ; i <= M + 1 ; i ++ ) s2 . add ( i ) ; for ( var i = 0 ; i < h ; i ++ ) { s1 . delete ( H [ i ] ) ; } for ( var i = 0 ; i < v ; i ++ ) { s2 . delete ( V [ i ] ) ; } var list1 = Array ( s1 . size ) ; var list2 = Array ( s2 . size ) ; var i = 0 ; s1 . forEach ( element => { list1 [ i ++ ] = element ; } ) ; i = 0 ; s2 . forEach ( element => { list2 [ i ++ ] = element ; } ) ; list1 . sort ( ( a , b ) => a - b ) list2 . sort ( ( a , b ) => a - b ) var maxH = 0 , p1 = 0 , maxV = 0 , p2 = 0 ; for ( var j = 0 ; j < s1 . size ; j ++ ) { maxH = Math . max ( maxH , list1 [ j ] - p1 ) ; p1 = list1 [ j ] ; } for ( var j = 0 ; j < s2 . size ; j ++ ) { maxV = Math . max ( maxV , list2 [ j ] - p2 ) ; p2 = list2 [ j ] ; } document . write ( maxV * maxH ) ; } var N = 3 , M = 3 ; var H = [ 2 ] ; var V = [ 2 ] ; var h = H . length ; var v = V . length ; largestArea ( N , M , H , V , h , v ) ;