Maximum number of overlapping rectangles with at least one common point | Function to find the maximum number of overlapping rectangles ; Stores the maximum count of overlapping rectangles ; Stores the X and Y coordinates ; Iterate over all pairs of Xs and Ys ; Store the count for the current X and Y ; Update the maximum count of rectangles ; Returns the total count ; Driver Code
def maxOverlappingRectangles ( x1 , y1 , x2 , y2 , N ) : NEW_LINE INDENT max_rectangles = 0 NEW_LINE X = [ ] NEW_LINE Y = [ ] NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT X . append ( x1 [ i ] ) NEW_LINE X . append ( x2 [ i ] - 1 ) NEW_LINE Y . append ( y1 [ i ] ) NEW_LINE Y . append ( y2 [ i ] - 1 ) NEW_LINE DEDENT for i in range ( 0 , len ( X ) ) : NEW_LINE INDENT for j in range ( 0 , len ( Y ) ) : NEW_LINE INDENT cnt = 0 NEW_LINE for k in range ( 0 , N ) : NEW_LINE INDENT if ( X [ i ] >= x1 [ k ] and X [ i ] + 1 <= x2 [ k ] and Y [ j ] >= y1 [ k ] and Y [ j ] + 1 <= y2 [ k ] ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT max_rectangles = max ( max_rectangles , cnt ) NEW_LINE DEDENT DEDENT print ( max_rectangles ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT x1 = [ 0 , 50 ] NEW_LINE y1 = [ 0 , 50 ] NEW_LINE x2 = [ 100 , 60 ] NEW_LINE y2 = [ 100 , 60 ] NEW_LINE N = len ( x1 ) NEW_LINE maxOverlappingRectangles ( x1 , y1 , x2 , y2 , N ) NEW_LINE DEDENT