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
Minimum Area Rectangle II: Find Smallest RectangleInput: Points[1,2][2,1][1,0][0,1]Process: Find RectanglesRectangle Found!Output: Minimum Area2.0Smallest AreaStep 1: Parse coordinate pointsStep 2: Check all combinations for rectanglesStep 3: Return minimum area foundKey: Rectangles can be rotated at any angle!Use diagonal properties: center point and 90° rotation
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
Asked in
Google 15 Amazon 8 Microsoft 12
28.0K Views
Medium Frequency
~25 min Avg. Time
834 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen