Maximum Area Rectangle With Point Constraints II - Problem
There are n points on an infinite plane. You are given two integer arrays xCoord and yCoord where (xCoord[i], yCoord[i]) represents the coordinates of the ith point.
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
$
Input:
xCoord = [1,1,3,3], yCoord = [1,3,1,3]
›
Output:
4
💡 Note:
Four points form a 2×2 rectangle with corners at (1,1), (1,3), (3,1), (3,3). No other points inside, area = 2×2 = 4
Example 2 — Point Inside Rectangle
$
Input:
xCoord = [1,1,3,3,2], yCoord = [1,3,1,3,2]
›
Output:
-1
💡 Note:
Point (2,2) lies inside any rectangle formed by the corner points, making no valid rectangle possible
Example 3 — Multiple Valid Rectangles
$
Input:
xCoord = [1,1,3,3,5,5], yCoord = [1,3,1,3,1,3]
›
Output:
8
💡 Note:
Two rectangles possible: (1,1)-(3,3) with area 4, and (3,1)-(5,3) with area 4. Maximum area is 4, but (1,1)-(5,3) gives area 4×2=8
Constraints
- 1 ≤ xCoord.length ≤ 2000
- xCoord.length == yCoord.length
- -105 ≤ xCoord[i], yCoord[i] ≤ 105
- All points are unique
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code