Minimum Area Rectangle - Problem
You are given an array of points in the X-Y plane points where points[i] = [xi, yi].
Return the minimum area of a rectangle formed from these points, with sides parallel to the X and Y axes.
If there is no such rectangle, return 0.
Input & Output
Example 1 — Basic Rectangle
$
Input:
points = [[1,1],[1,3],[3,1],[3,3]]
›
Output:
4
💡 Note:
The four points form a rectangle with corners at (1,1), (1,3), (3,1), (3,3). Width = 3-1 = 2, Height = 3-1 = 2, Area = 2×2 = 4.
Example 2 — Multiple Rectangles
$
Input:
points = [[1,1],[1,3],[3,1],[3,3],[2,2]]
›
Output:
4
💡 Note:
Even with an extra point (2,2), the same rectangle from example 1 is still the only valid rectangle, so minimum area remains 4.
Example 3 — No Rectangle Possible
$
Input:
points = [[1,1],[1,3],[3,1]]
›
Output:
0
💡 Note:
Only 3 points provided. Need at least 4 points to form a rectangle, so return 0.
Constraints
- 1 ≤ points.length ≤ 500
- points[i].length == 2
- 0 ≤ xi, yi ≤ 4×104
- All the given points are unique
Visualization
Tap to expand
Understanding the Visualization
1
Input Points
Given set of coordinate points
2
Find Rectangles
Identify all possible rectangles with axis-parallel sides
3
Minimum Area
Return the smallest rectangle area
Key Takeaway
🎯 Key Insight: A rectangle is uniquely determined by two diagonal points - use this to reduce from O(n⁴) to O(n²)
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code