The Minimum Area Rectangle II is the harder sibling of the previous problem. Here, the rectangle's sides do not have to be parallel to the X and Y axes. You can form a rectangle at any angle. Given a set of points, you must find the minimum area of any valid rectangle.
This Minimum Area Rectangle II interview question is a favorite at Google and Verily for high-level candidates. It tests advanced geometry and the ability to use complex keys in a Hash Map. It requires knowledge of the property that a rectangle's diagonals are equal in length and bisect each other.
The Geometry and Hash Map interview pattern used here relies on diagonal properties:
(p1, p2) can be a potential diagonal.(x_mid, y_mid).(length, x_mid, y_mid). Store all pairs of points that share the same diagonal properties.Imagine four points forming a tilted square.
(0,0) to (2,2). Midpoint (1,1), Length squared 8.(0,2) to (2,0). Midpoint (1,1), Length squared 8.In 2D geometry, look for invariants. For rectangles, the invariant is the diagonal. For circles, it's the center and radius. Using these as keys in a Hash Map is a powerful technique for reducing complexity from to .
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Convex Polygon | Medium | Solve | |
| Queries on Number of Points Inside a Circle | Medium | Solve | |
| Find the Largest Area of Square Inside Two Rectangles | Medium | Solve | |
| Erect the Fence II | Hard | Solve | |
| Valid Boomerang | Easy | Solve |