Imagine you're a city planner working with a grid-based map where certain locations are marked as special landmarks. Your task is to find the largest rectangular park that can be built using exactly four of these landmarks as corners.
Given n points on an infinite 2D plane with coordinates (xCoord[i], yCoord[i]), you need to find the maximum area rectangle that:
- Uses exactly four points as its corners
- Has edges parallel to the axes (axis-aligned)
- Contains no other points inside or on its borders
Return the maximum area possible, or -1 if no valid rectangle can be formed.
Example: With points [(1,1), (1,3), (3,1), (3,3), (2,2)], the rectangle with corners (1,1), (1,3), (3,1), (3,3) would be invalid because (2,2) lies inside it.
Input & Output
Time & Space Complexity
O(n^4) to check all 4-point combinations, O(n) to verify each rectangle is empty
Only storing constant amount of variables