Minimum Area Rectangle II - Problem
You are given an array of points in the X-Y plane points where points[i] = [xi, yi]. Return the minimum area of any rectangle formed from these points, with sides not necessarily parallel to the X and Y axes.
If there is no such rectangle, return 0.
Answers within 10-5 of the actual answer will be accepted.
Input & Output
Example 1 — Basic Rectangle
$
Input:
points = [[1,2],[2,1],[1,0],[0,1]]
›
Output:
2.0
💡 Note:
These 4 points form a square rotated 45 degrees with side length √2, so area = (√2)² = 2.0
Example 2 — No Rectangle
$
Input:
points = [[1,1],[1,3],[3,1]]
›
Output:
0.0
💡 Note:
Only 3 points given, cannot form any rectangle, return 0
Example 3 — Multiple Rectangles
$
Input:
points = [[0,0],[1,0],[2,0],[0,1],[1,1],[2,1]]
›
Output:
1.0
💡 Note:
Multiple rectangles possible, smallest has area 1.0 (1×1 square)
Constraints
- 1 ≤ points.length ≤ 50
- 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 array of coordinate points in 2D plane
2
Find Rectangles
Identify all valid rectangles (any orientation)
3
Return Minimum
Calculate and return the smallest area found
Key Takeaway
🎯 Key Insight: Use the fact that rectangle diagonals bisect each other to efficiently find all valid rectangles
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code