- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have an array called rect where rect[i] has two elements [len_i, wid_i], where len_i and wid_i are representing the length and width of ith rectangle respectively. Now we can cut the ith rectangle to form a square whose side length is of k if both k <= lenn_i and k <= wid_i. So for example, if we have a rectangle [4,6], then we can cut it to get a square with a side length of at most 4. Now consider a parameter called maxLen be the side length of the largest square we can get from any of the given rectangles. We have to find the number of rectangles that we can make a square with a side length of maxLen.

So, if the input is like rect = [[6,9],[4,10],[6,13],[17,6]], then the output will be 3 as we can get largest squares of sides [6, 4, 6, 6], so there are three rectangles which are largest.

To solve this, we will follow these steps −

m := a new list

for each r in rect, do

insert minimum of r at the end of m

count (maximum of m) present in m and return

Let us see the following implementation to get better understanding −

def solve(rect): m = [] for r in rect: m.append(min(r)) return m.count(max(m)) rect = [[6,9],[4,10],[6,13],[17,6]] print(solve(rect))

[[6,9],[4,10],[6,13],[17,6]]

3

- Related Questions & Answers
- Program to find number of boxes that form longest chain in Python?
- Python program to find the largest number in a list
- Area of the Largest square that can be inscribed in an ellipse in C++
- Program to find area of largest square of 1s in a given matrix in python
- Program to find number of square submatrices with 1 in python
- 8086 program to find the square root of a perfect square root number
- Python program to find largest number in a list
- Python program to find the second largest number in a list
- Find the largest number that can be formed with the given digits in C++
- Python Program for Find largest prime factor of a number
- 8085 program to find square root of a number
- 8086 program to find Square Root of a number
- Java program to find the square root of a given number
- Java program to find the largest number in an array
- Program to find the sum of largest K sublist in Python

Advertisements