The Minimum Area Rectangle problem gives you a list of coordinates (x, y) on a 2D plane. You need to find the minimum area of a rectangle formed from these points, such that the rectangle's sides are parallel to the X and Y axes. If no such rectangle can be formed, you return 0.
This is a classic Minimum Area Rectangle interview question asked at Google, Meta, and Flipkart. It tests your ability to use Hash Tables for fast lookups and your geometric reasoning. It evaluates if you can identify that a rectangle is uniquely defined by its diagonal points (x1, y1) and (x2, y2).
The Hash Table interview pattern is crucial here.
p1 and p2.p1.x != p2.x and p1.y != p2.y, they could be the diagonal of a rectangle.(p1.x, p2.y) and (p2.x, p1.y), exist in your Set.|p1.x - p2.x| * |p1.y - p2.y| and track the minimum.Points: (1,1), (1,3), (3,1), (3,3), (4,1), (4,3).
(1,1) and (3,3) as diagonals.(1,3) and (3,1) exist. They do! Area = 2 * 2 = 4.(3,1) and (4,3) as diagonals.(3,3) and (4,1) exist. They do! Area = 1 * 2 = 2.2.Geometry problems in coding interviews often boil down to Hash Table lookups. If you can define a shape by a subset of its points (like a diagonal for a rectangle or a center/radius for a circle), you can use the Set to verify the existence of the remaining points.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Max Points on a Line | Hard | Solve | |
| Count Number of Trapezoids II | Hard | Solve | |
| Find the Number of Ways to Place People I | Medium | Solve | |
| Minimum Lines to Represent a Line Chart | Medium | Solve | |
| Maximum Number of Intersections on the Chart | Hard | Solve |