Find the Smallest Rectangle Area with Arbitrarily Oriented Sides

Quick Overview

Find the Smallest Rectangle Area with Arbitrarily Oriented Sides. Choose four points from points that are the vertices of a nondegenerate rectangle.

Find the Smallest Rectangle Area with Arbitrarily Oriented Sides

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Choose four points from `points` that are the vertices of a nondegenerate rectangle. Its sides may be tilted relative to the coordinate axes. Return the smallest such area, or0 if no rectangle exists. Answers within `10^-5` of the true answer are accepted. ```cpp class Solution { public: double minAreaFreeRect(vector<vector<int>>& points); }; ``` ### Examples **Example 1:** ```text Input: points = [[1,1],[1,4],[3,1],[3,4]] Output: 6.00000 Explanation: The only four-point rectangle has side lengths3 and2. ``` **Example 2:** ```text Input: points = [[2,0],[4,2],[2,4],[0,2]] Output: 8.00000 Explanation: These points form a tilted square whose adjacent edge vectors(2,2) and(-2,2) have cross-product magnitude8. ``` ### Constraints - `1 <= points.length <= 50`. - Every point has exactly two coordinates. - `0 <= x_i,y_i <= 4*10^4`. - All points are unique. - Answers within `10^-5` of the actual area are accepted. ### Contract considerations The API returns double with an absolute error allowance of10^-5; it is a unique minimum-area value, not a free construction output. ```hint Read the boundary condition Given a right angle at one corner, where must the fourth corner lie? ``` ### Boundary reminders The API returns double with an absolute error allowance of10^-5; it is a unique minimum-area value, not a free construction output.

Overview: Find the Smallest Rectangle Area with Arbitrarily Oriented Sides. Choose four points from points that are the vertices of a nondegenerate rectangle.

Google logo
Google
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Choose four points from points that are the vertices of a nondegenerate rectangle. Its sides may be tilted relative to the coordinate axes. Return the smallest such area, or0 if no rectangle exists. Answers within 10^-5 of the true answer are accepted.

class Solution {
public:
    double minAreaFreeRect(vector<vector<int>>& points);
};

Examples

Example 1:

Input: points = [[1,1],[1,4],[3,1],[3,4]]
Output: 6.00000
Explanation: The only four-point rectangle has side lengths3 and2.

Example 2:

Input: points = [[2,0],[4,2],[2,4],[0,2]]
Output: 8.00000
Explanation: These points form a tilted square whose adjacent edge vectors(2,2) and(-2,2) have cross-product magnitude8.

Constraints

  • 1 <= points.length <= 50 .
  • Every point has exactly two coordinates.
  • 0 <= x_i,y_i <= 4*10^4 .
  • All points are unique.
  • Answers within 10^-5 of the actual area are accepted.

Contract considerations

The API returns double with an absolute error allowance of10^-5; it is a unique minimum-area value, not a free construction output.

Boundary reminders

The API returns double with an absolute error allowance of10^-5; it is a unique minimum-area value, not a free construction output.