Minimum Area Rectangle
From LeetCode. Min area from points (axis-aligned). Solve the geometry problem "Minimum Area Rectangle".
Examples
Input: [1,2,3]
Output: 0
Input: [2,3,4]
Output: 0
Hints
An axis-aligned rectangle needs two points sharing the same x (vertical edge) and two points sharing another x (opposite vertical edge), with matching y-coordinates. Group points by x-coordinate.
For each pair of points (y1, y2) sharing the same x, store the y-pair in a dictionary keyed by (y1, y2) with the x-coordinate as the value. When you see the same y-pair at a different x2, you have a rectangle with area |x2 - x1| * |y2 - y1|.
Iterate left to right over x groups. For each y in the current x group, check a "last seen x" map keyed by y — if y was seen at a previous x, compute candidate rectangles using all y's in the current x group. This achieves O(n²) without needing to track duplicate y-pairs explicitly.
Minimum Area Rectangle
**From LeetCode.** Min area from points (axis-aligned). Solve the geometry problem "Minimum Area Rectangle".