All problems
1077MediumArrayHash TableMathGeometrySorting

The Smallest Upright Frame

Tracked in this browser only
Write code

Trains the technique from

LeetCode 939Minimum Area Rectangle

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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