Given two rectangles, X with a ratio of length to width a:b and Y with a ratio of length to width c:d respectively. Both the rectangles can be resized as long as the ratio of sides remains the same. The task is to place the second rectangle inside the first rectangle such that at least 1 side is equal and that side overlaps of both the rectangles and find the ratio of (space occupied by a 2nd rectangle) : (space occupied by the first rectangle).
Input: a = 1, b = 1, c = 3, d = 2 Output: 2:3 The dimensions can be 3X3 and 3X2. Input: a = 4, b = 3, c = 2, d = 2 Output: 3:4 The dimensions can be 4X3 and 3X3
Approach: If we make one of the sides of rectangles equal then the required ratio would be the ratio of the other side.
Consider 2 cases:
- a*d < b*c : We should make a and c equal.
- b*c < a*d : We should make b and d equal.
Since multiplying both sides of a ratio does not change its value. First try to make a and c equal, it can be made equal to their lcm by multiplying (a:b) with lcm/a and (c:d) with lcm/c. After multiplication, the ratio of (b:d) will be the required answer. This ratio can be reduced by dividing b and d with gcd(b, d).
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.
- Area of a circle inscribed in a rectangle which is inscribed in a semicircle
- Area of a triangle inscribed in a rectangle which is inscribed in an ellipse
- Area of largest triangle that can be inscribed within a rectangle
- Area of Largest rectangle that can be inscribed in an Ellipse
- Area of the biggest possible rhombus that can be inscribed in a rectangle
- Area of the biggest ellipse inscribed within a rectangle
- Maximum area of rectangle inscribed in an equilateral triangle
- Radius of the biggest possible circle inscribed in rhombus which in turn is inscribed in a rectangle
- Largest ellipse that can be inscribed within a rectangle which in turn is inscribed within a semicircle
- Area of the largest Rectangle without a given point
- Maximum area of rectangle possible with given perimeter
- Sum of Area of all possible square inside a rectangle
- Program for Area And Perimeter Of Rectangle
- Number of squares of maximum area in a rectangle
- Find minimum area of rectangle with given set of coordinates
- Find the percentage change in the area of a Rectangle
- Rectangle with Maximum Area using Java Pair
- Maximum area rectangle by picking four sides from array
- Area of a square inscribed in a circle which is inscribed in an equilateral triangle
- Area of a square inscribed in a circle which is inscribed in a hexagon
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.