Talentd
FleetCode

939. Minimum Area Rectangle

Medium55.4% acceptance8 companies

You are given an array of points in the X-Y plane points where points[i] = [xi, yi].

Return the minimum area of a rectangle formed from these points, with sides parallel to the X and Y axes. If there is not any such rectangle, return 0.

Example 1:

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

Example 2:

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

Constraints:

  • 1 <= points.length <= 500
  • points[i].length == 2
  • 0 <= xi, yi <= 4 * 104
  • All the given points are unique.
14:16
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def minAreaRect(self, points: List[List[int]]) -> int:
3
Starter codePython 3Spaces: 4
Examples
Input
[[1,1],[1,3],[3,1],[3,3],[2,2]]
Input
[[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]]
Your code is saved on this device.Solution