human
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.
Driver code.
Given value of N & M.
Given arrays.
Function call to find the largest area when a series of horizontal & vertical bars are removed"
How can the above be solved in Python?
assistant
#Here is code to largest area possible after removal of a series of horizontal & vertical bars and the other steps required.
 def largestArea ( N , M , H , V , h , v ) :
	s1 = set ( [ ] ) ;
	s2 = set ( [ ] ) ;
	for i in range ( 1 , N + 2 ) :
		s1 . add ( i ) ;
	for i in range ( 1 , M + 2 ) :
		s2 . add ( i ) ;
	for i in range ( h ) :
		s1 . remove ( H [ i ] ) ;
	for i in range ( v ) :
		s2 . remove ( V [ i ] ) ;
	list1 = [ 0 ] * len ( s1 )
	list2 = [ 0 ] * len ( s2 ) ;
	i = 0 ;
	for it1 in s1 :
		list1 [ i ] = it1 ;
		i += 1
	i = 0 ;
	for it2 in s2 :
		list2 [ i ] = it2
		i += 1
	list1 . sort ( ) ;
	list2 . sort ( ) ;
	maxH = 0
	p1 = 0
	maxV = 0
	p2 = 0 ;
	for j in range ( len ( s1 ) ) :
		maxH = max ( maxH , list1 [ j ] - p1 ) ;
		p1 = list1 [ j ] ;
	for j in range ( len ( s2 ) ) :
		maxV = max ( maxV , list2 [ j ] - p2 ) ;
		p2 = list2 [ j ] ;
	print ( ( maxV * maxH ) )
if __name__ == " _ _ main _ _ " :
	N = 3
	M = 3 ;
	H = [ 2 ]
	V = [ 2 ] ;
	h = len ( H )
	v = len ( V ) ;
	largestArea ( N , M , H , V , h , v ) ;