Description

Given points in 2D, find the minimum area of an axis-aligned rectangle formed by 4 of the points. Return 0 if no rectangle exists.

Examples

Input:points = [[1,1],[1,3],[3,1],[3,3],[2,2]]
Output:4
Explanation:

Rectangle with corners (1,1), (1,3), (3,1), (3,3).

Input:points = [[1]]
Output:1
Explanation:

Minimal case with a single point.

Input:points = [[0,0],[0,4],[2,0],[2,4],[5,1],[5,3],[7,1],[7,3]]
Output:4
Explanation:

Two possible rectangles can be formed: one with corners (0,0), (0,4), (2,0), (2,4) having area 8, and another with corners (5,1), (5,3), (7,1), (7,3) having area 4. The minimum area is 4.

Constraints

  • 1 ≤ points.length ≤ 500

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!