Given n number of rectangles with it’s L-length and B-Breadth. We can turn any rectangle by 90 degrees. In other words, after turning them, the breadth will become length and length will be breadth.
The task is to check if there is a way to make the rectangles go in order of non-ascending breadth. That is, a breadth of every rectangle has to be not greater than the breadth of the previous rectangle.
Note: You can not change the order of the rectangles.
l = 3, b = 4
l1 = 4, b1 = 6
l2 = 3, b2 = 5
The given breadths are [ 4, 6, 5 ] we can rotate the second and the third rectangle so that the breadths will satisfy the above condition [ 4, 4, 3 ] ( 3 is not greater than 4 and 4 is not greater than 4 ) which is why we print YES.
The breadths are [ 60, 55, 80 ] as 55 55 or 56 > 55. So it’s not possible to arrange the breadths in non-ascending order, which is why we’ll print NO.
Approach: Below is the step by step algorithm to solve this problem:
- Initialize n rectangle with their lengths and breadths.
- Iterate over the rectangle from left to right.
- Turn each rectangle in such a way that it’s breadth is as big as possible but not greater than the previous rectangle.
- If on some iteration there is no such way to place the rectangle, the answer is “NO”
Below is the implementation of above approach:
- Rearrange all elements of array which are multiples of x in increasing order
- Rearrange Odd and Even values in Alternate Fashion in Ascending Order
- Check if N rectangles of equal area can be formed from (4 * N) integers
- Rearrange an array in order - smallest, largest, 2nd smallest, 2nd largest, ..
- Check if a number has digits in the given Order
- Check if words are sorted according to new order of alphabets
- Check if the characters of a given string are in alphabetical order
- Check if value exists in level-order sorted complete binary tree
- Find if two rectangles overlap
- Sum of Areas of Rectangles possible for an array
- Number of rectangles in N*M grid
- Count Distinct Rectangles in N*N Chessboard
- Number of rectangles in a circle of radius R
- Smallest square formed with given rectangles
- Total area of two overlapping rectangles
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.