DIY: Minimum Area Rectangle
Solve the interview question "Minimum Area Rectangle" in this lesson.
We'll cover the following
Problem statement
Given an array of points in the X-Y plane points
, where points[i] = [xi, yi]
, you have to return the minimum area of a rectangle formed from these points, with sides parallel to the X and Y axes. If there is no such rectangle that can be formed, you will return 0
.
Constraints
You can assume the following constraints for this problem:
-
1 <= points.size() <= 500
-
points[i].size() == 2
-
0 <= xi, yi <= 4 * 104
Input
The input will be a 2D array of integers, where the nested arrays will represent a single point of the form [x, y]
. Here are a few examples of the inputs:
// Example - 1
[[1,0],[1,3],[3,0],[3,3]]
// Example - 2
[[1, 1], [1, 2], [1, 3], [1, 4]]
Output
The output will be an integer that will represent the minimum area of a rectangle that can be formed from the given input points:
// Example - 1
4
// Example - 2
0
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.