Largest Rectangle From Points
GoogleOnsiteMedium
You are given distinct points on a plane with integer coordinates. A rectangle is formed when four of the points are its corners. The rectangle's sides do not have to be parallel to the axes. A square counts as a rectangle.
Part 1: Largest rectangle area
Given a list of distinct points points, where each point is [x, y] with integer coordinates, return the largest area of a rectangle whose four corners are all in points.
The sides of the rectangle do not have to be parallel to the axes. A square counts as a rectangle.
Return 0 when no four points form a rectangle. The area of a rectangle with integer corners is always an integer, so return an int.
- Example 1
- points
[[0,0],[0,2],[3,0],[3,2],[1,1]]- Output
6
Why: The corners (0, 0), (3, 0), (3, 2), (0, 2) form a 3 by 2 rectangle, so the area is 6. The point (1, 1) is not a corner of anything larger.
- Example 2
- points
[[1,0],[3,1],[2,3],[0,2],[0,0]]- Output
5
Why: The four points (1, 0), (3, 1), (2, 3), (0, 2) have sides (2, 1) and (-1, 2): perpendicular and both of length sqrt(5), a square of area 5. (0, 0) is unused.
Constraints
0 <= len(points) <= 1000-10^4 <= points[i][0] <= 10^4-10^4 <= points[i][1] <= 10^4pointsvalues are pairwise distinct