Show problems as
Classic problem #939MediumArrayHash TableMathGeometrySorting

Minimum Area Rectangle

Real-world version: The Smallest Upright Frame
Tracked in this browser only
Read Minimum Area Rectangle on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

Pins are placed at the positions pins, where pins[i] = [x, y], and no two pins share a position.

A frame is a rectangle whose four corners are pins and whose sides run parallel to the axes.

Return the smallest area any frame encloses, or 0 when no four pins form one.

Examples

Example 1

Input
pins = [[0, 0], [0, 2], [2, 0], [2, 2]]
Output
4

The four pins are the corners of a square two wide and two tall, enclosing four.

Example 2

Input
pins = [[0, 0], [1, 1]]
Output
0

Two pins cannot make four corners, so there is no frame at all.

Example 3

Input
pins = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 0], [2, 1]]
Output
1

Three columns each hold a pin at both heights, and the closest two columns are one apart, giving a frame one wide and one tall.

Constraints

  • 1 <= pins.length <= 500
  • pins[i].length == 2
  • 0 <= pins[i][0] <= 40000
  • 0 <= pins[i][1] <= 40000
  • No two pins share a position.

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def min_area_rect(pins: list[list[int]]) -> int:
Java
public int minAreaRect(int[][] pins)