All problems
0872MediumArrayHash TableMathGeometry

Smallest Slanted Frame

Tracked in this browser only
Write code

Trains the technique from

LeetCode 963Minimum Area Rectangle II

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.

A set of pin positions is given as points, each [x, y], and all of them are distinct.

A frame is four of those pins forming a rectangle. The rectangle's sides need not run along the axes, so a slanted rectangle counts.

Return the smallest area any frame can have, or 0.0 when no four pins form a rectangle. An answer within 1e-5 of the true value is accepted.

Examples

Example 1

Input
points = [[2, 10], [6, 13], [12, 5], [8, 2]]
Output
50.0

The four pins form a rectangle standing at a slant. Its two diagonals both run between the midpoint 7, 7.5 and are the same length, and its sides measure 5 and 10, so the area is 50.

Example 2

Input
points = [[0, 0], [1, 0], [2, 0], [3, 0]]
Output
0.0

Every pin sits on one line, so no four of them form a rectangle.

Example 3

Input
points = [[0, 0], [0, 1], [1, 0], [1, 1], [2, 0], [2, 1]]
Output
1.0

The smallest rectangle takes two neighbouring columns of pins, giving sides of 1 and 1.

Constraints

  • 1 <= points.length <= 50
  • points[i].length == 2
  • 0 <= points[i][0] <= 40000
  • 0 <= points[i][1] <= 40000
  • All the pin positions are distinct

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 smallest_slanted_frame(points: list[list[int]]) -> float:
Java
public double smallestSlantedFrame(List<List<Integer>> points)
September 7
Apply