Largest Rectangle From Points

Asked at GoogleOnsite

Reported by the problem's creator, not verified

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.

Examples

  1. Example 1

    Input: points = [[0,0],[0,2],[3,0],[3,2],[1,1]]

    Output: 6

    Explanation: 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.

  2. Example 2

    Input: points = [[1,0],[3,1],[2,3],[0,2],[0,0]]

    Output: 5

    Explanation: 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.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.