Maximum Area Rectangle With Point Constraints I - Problem
You are given an array points where points[i] = [xi, yi] represents the coordinates of a point on an infinite plane.
Your task is to find the maximum area of a rectangle that:
- Can be formed using four of these points as its corners
- Does not contain any other point inside or on its border
- Has its edges parallel to the axes
Return the maximum area that you can obtain or -1 if no such rectangle is possible.
Input & Output
Example 1 — Valid Rectangle Found
$
Input:
points = [[1,1],[1,3],[3,1],[3,3],[2,2]]
›
Output:
4
💡 Note:
Points [1,1], [1,3], [3,1], [3,3] form a 2×2 rectangle with area 4. Point [2,2] is inside, so this rectangle is invalid. No other valid rectangles exist, but let's say we had points without [2,2] - then area would be 4.
Example 2 — No Valid Rectangle
$
Input:
points = [[1,1],[1,3],[3,1],[3,3],[2,2]]
›
Output:
-1
💡 Note:
The only potential rectangle has point [2,2] inside it, making it invalid. No other combination of 4 points can form a valid rectangle.
Example 3 — Multiple Valid Rectangles
$
Input:
points = [[1,1],[1,3],[3,1],[3,3],[4,4],[4,6],[6,4],[6,6]]
›
Output:
4
💡 Note:
Two valid rectangles: [1,1],[1,3],[3,1],[3,3] with area 4, and [4,4],[4,6],[6,4],[6,6] with area 4. Maximum area is 4.
Constraints
- 4 ≤ points.length ≤ 3000
- -105 ≤ xi, yi ≤ 105
- All points are distinct
Visualization
Tap to expand
Understanding the Visualization
1
Input Points
Given set of coordinate points on a plane
2
Find Rectangles
Identify all possible axis-aligned rectangles using 4 points
3
Validate & Maximize
Ensure no points inside, return maximum area or -1
Key Takeaway
🎯 Key Insight: Use diagonal point pairs to efficiently validate rectangles instead of checking all 4-point combinations
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code