#162 · Dictionaries and sets · Advanced · 150 XP · about 28 min
points is a list of different points [x, y] on a grid. Write min_rectangle_area(points) that returns the smallest area of a rectangle whose four corners are all points in the list and whose sides are parallel to the x and y axes. Return 0 if there is no such rectangle.
min_rectangle_area([[1, 1], [1, 3], [3, 1], [3, 3], [2, 2]]) # returns 4 min_rectangle_area([[1, 1], [1, 3], [3, 1], [3, 3], [4, 1], [4, 3]]) # returns 2 min_rectangle_area([[0, 0], [1, 1]]) # returns 0
In the second example the rectangle with corners at x = 3 and x = 4 (and y = 1 and y = 3) has area 2.
0 <= len(points) <= 500-10**4 and 10**4Ready?
Accept the challenge to start writing. A small timer counts the time this page is in view.
Output appears here.