Last Updated: March 28, 2026
This problem is a step up from the classic "Minimum Area Rectangle" (LeetCode #939) where rectangles had to be axis-aligned. Here, the rectangle can be rotated at any angle. That changes the problem fundamentally, because we can no longer just look for pairs of points sharing an x-coordinate or y-coordinate.
What makes a rectangle a rectangle? Four points where opposite sides are equal and parallel, and all angles are 90 degrees. In coordinate geometry, this means the diagonals of a rectangle bisect each other (share the same midpoint) and have equal length. That geometric property is the key observation that unlocks the efficient solution.
1 <= points.length <= 50 → With n up to 50, even O(n^4) would be at most 6.25 million operations, which is perfectly fine. O(n^3) and O(n^2) approaches are also viable.0 <= xi, yi <= 4 * 10^4 → Coordinates are non-negative integers. This means we can use them as hash keys without worrying about floating-point issues in point lookups.All points are unique → No need to handle duplicate points.The most natural approach: pick any three points and figure out where the fourth point of the rectangle would need to be. If that fourth point exists in our set, we have a valid rectangle.
If we pick three points A, B, C and assume A is the corner with the right angle, then vectors AB and AC must be perpendicular. We can check perpendicularity with the dot product: if AB dot AC = 0, the angle at A is 90 degrees. The fourth point D is then B + C - A (the opposite corner of the rectangle).
For each of the n points, we check all O(n^2) pairs of remaining points to see if they form a right angle at that vertex. Many triples fail the perpendicularity check. We are spending time on combinations that can never form rectangles.
What if instead of checking triples, we grouped pairs of points by a property that guarantees they can form a rectangle together?
In any rectangle, the two diagonals bisect each other. That means both diagonals share the same midpoint and have the same length. So if we take all pairs of points and compute their midpoint and distance, any two pairs sharing the same (midpoint, distance) are the two diagonals of a potential rectangle.
A rectangle has two diagonals that always share the same midpoint and have the same length. By grouping point pairs that share both of these properties, we guarantee that any two pairs from the same group are the two diagonals of a valid rectangle. The area computation uses the cross product of the side vectors from one corner.