Given the length L and breadth B of two identical rectangles, the task is to find the minimum area of a square in which the two identical rectangles with dimensions L × B can be embedded.
Input: L = 7, B = 4
Explanation: Two rectangles with sides 7 x 4 can fit into square with side 8. By placing two rectangles with side 4 upon each other and the length of contact is 7.
Input: L = 1, B = 3
Explanation: Two rectangles with sides 1 x 3 can fit into square with side 3. By placing two rectangles with side 1 upon each other and a gap of 1 between the 2 rectangles.
- If one side of the rectangle is lesser than or equal to half the length of the other side then the side of the square is the longer side of the rectangle.
- If twice the length of the smaller side is greater than the larger side, then the side of the square is twice the length of the smaller side of the rectangle.
Below is the implementation of the above approach:
Time Complexity: O(1)
Auxiilary Space Complexity: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find side of Square which makes minimal area to fit two identical rectangles inside it
- Total area of two overlapping rectangles
- Check if N rectangles of equal area can be formed from (4 * N) integers
- Count of Rectangles with area K made up of only 1s from given Binary Arrays
- Smallest square formed with given rectangles
- Check if given two straight lines are identical or not
- Find the minimum number of rectangles left after inserting one into another
- Find if two rectangles overlap
- Intersecting rectangle when bottom-left and top-right corners of two rectangles are given
- Calculate Volume, Curved Surface Area and Total Surface Area Of Cylinder
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Find the next identical calendar year
- Count how many times the given digital clock shows identical digits
- Number of ways of distributing N identical objects in R distinct groups with no groups empty
- Number of ways of distributing N identical objects in R distinct groups
- Create a matrix with alternating rectangles of O and X
- Number of unique rectangles formed using N unit squares
- Number of rectangles in N*M grid
- Find all rectangles filled with 0
- Sum of Areas of Rectangles possible for an array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.