Given an array of set of points in the X-Y plane. The task is to find the minimum area of a rectangle that can be formed from these points. The sides of the rectangle should be parallel to the X and Y axes. If a rectangle cannot be formed with the given points then print .
Input: arr = [[1, 1], [1, 3], [3, 1], [3, 3], [2, 2]]
The only rectangle possible will be formed with the points (1, 1), (1, 3), (3, 1) and (3, 3)
Input: arr = [[1, 1], [1, 3], [3, 1], [3, 3], [4, 1], [4, 3]]
Approach: Group the points by coordinates, so that points on straight vertical lines are grouped together. Then, for every pair of points in a group, for eg. coordinates (X, Y1) and (X, Y2), we check for the smallest rectangle with this pair of points as the rightmost edge of the rectangle to be formed. We can do this by keeping track of all other pairs of points we’ve visited before. Finally return the minimum possible area of the rectangle obtained.
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find the coordinates of a triangle whose Area = (S / 2)
- Find the percentage change in the area of a Rectangle
- Coordinates of rectangle with given points lie inside
- Ratio of area of a rectangle with the rectangle inscribed in it
- Area and Perimeter of Rectangle in PL/SQL
- Sum of Area of all possible square inside a rectangle
- Maximum area of rectangle possible with given perimeter
- Program for Area And Perimeter Of Rectangle
- Area of the largest Rectangle without a given point
- Area of the biggest possible rhombus that can be inscribed in a rectangle
- Rectangle with Maximum Area using Java Pair
- Number of squares of maximum area in a rectangle
- Area of Largest rectangle that can be inscribed in an Ellipse
- Area of largest triangle that can be inscribed within a rectangle
- Area of the biggest ellipse inscribed within a rectangle
- Maximum area rectangle by picking four sides from array
- Maximum area of rectangle inscribed in an equilateral triangle
- Minimum length of square to contain at least half of the given Coordinates
- Minimum Manhattan distance covered by visiting every coordinates from a source to a final vertex
- Find all possible coordinates of parallelogram
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : mohit kumar 29