Minimum Area Rectangle
Real-world version: The Smallest Upright FrameThe 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.
def min_area_rect(pins: list[list[int]]) -> int:public int minAreaRect(int[][] pins)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 18 test cases: 18 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's