Count rectangles generated in a given rectangle by lines drawn parallel to X and Y axis from a given set of points | Function to get the count of ractangles ; Store distinct horizontal lines ; Store distinct Vertical lines ; Insert horizontal line passing through 0 ; Insert vertical line passing through 0. ; Insert horizontal line passing through rectangle [ 3 ] [ 0 ] ; Insert vertical line passing through rectangle [ 3 ] [ 1 ] ; Insert all horizontal and vertical lines passing through the given array ; Insert all horizontal lines ; Insert all vertical lines ; Driver Code
def cntRect ( points , N , rectangle ) : NEW_LINE INDENT cntHor = set ( [ ] ) NEW_LINE cntVer = set ( [ ] ) NEW_LINE cntHor . add ( 0 ) NEW_LINE cntVer . add ( 0 ) NEW_LINE cntHor . add ( rectangle [ 3 ] [ 0 ] ) NEW_LINE cntVer . add ( rectangle [ 3 ] [ 1 ] ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT cntHor . add ( points [ i ] [ 0 ] ) NEW_LINE cntVer . add ( points [ i ] [ 1 ] ) NEW_LINE DEDENT return ( ( len ( cntHor ) - 1 ) * ( len ( cntVer ) - 1 ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT rectangle = [ [ 0 , 0 ] , [ 0 , 5 ] , [ 5 , 0 ] , [ 5 , 5 ] ] NEW_LINE points = [ [ 1 , 2 ] , [ 3 , 4 ] ] NEW_LINE N = len ( points ) NEW_LINE print ( cntRect ( points , N , rectangle ) ) NEW_LINE DEDENT