Question: Write a Python function count_rectangles that takes as arguments positive integers m and n and returns the number of distinct, non-degenerate rectangles in an integer

Write a Python function count_rectangles that takes as arguments positive integers m and n and returns the number of distinct, non-degenerate rectangles in an integer grid with vertical lines at z = 0,1,...,m and horizontal lines at y = 0, 1, ..., n. Example 1: Consider the case when m =1 and n=1. In this case the grid is only the unit square with lower-left vertex at (0,0) and upper-right vertex at (1,1). Thus, your function should return 1. Example 2: Consider the case when m = 2 and n=1 shown below. In this case there are 3 non-degenerate rectangles. The two small squares of side length 1, and the larger rectangle of side lengths 1 and 2. Thus, your function should return 3. (2, 1) (0, 0) Notes: There are 3 visible test cases and 2 hidden test cases. The inputs m and n will satisfy 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
