Ctrl K

Smallest Rectangle of Pins

Medium
Pins are stuck in a corkboard; their coordinates are given in pins, where pins[i] = [x, y]. You want to stretch a rubber band around four of the pins so that it forms a rectangle. The sides **don't have to** be parallel to the axes: the rectangle can be rotated any way. Return the smallest area of such a rectangle. If no four pins form a rectangle, return 0. Answers within 10⁻⁵ of the exact value are accepted.
Example 1
pins=[[0, 2], [2, 0], [3, 1], [1, 3]] → 4.000000000000001

These four points form a tilted rectangle with sides √8 and √2, so its area is 4.

Example 2
pins=[[0, 0], [0, 1], [1, 0], [1, 1], [2, 1], [1, 2]] → 1.0

There is a square [0, 0], [0, 1], [1, 1], [1, 0] of area 1 and a tilted square [1, 0], [2, 1], [1, 2], [0, 1] of area 2. The smaller one wins: 1.

Example 3
pins=[[0, 0], [1, 2], [3, 3]] → 0

Three points cannot make a rectangle, so the answer is 0.

Constraints
  • 1 ≤ len(pins) ≤ 50
  • pins[i] = [x, y], 0 ≤ x, y ≤ 4·10⁴
  • All pins are at distinct points
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsNo Inward Corners MediumSmallest Paddock MediumNearest Points to the Base MediumDevices in Router Range MediumLongest Firework Chain Medium
loading Python…
Input
pins=[[0, 2], [2, 0], [3, 1], [1, 3]]
Expected
4.000000000000001

Run checks the first 3 tests in your browser. Submit checks all 101 tests on the server, hidden ones included.