- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions

# Program to find number of rectangles that can form the largest square in Python

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

## Example (Python)

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))

## Input

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

## Output

3

- Related Articles
- Program to find number of boxes that form longest chain in Python?
- Python program to find the largest number in a list
- Python program to find largest number in a list
- Python program to find the second largest number in a list
- Program to find area of largest square of 1s in a given matrix in python
- Program to find out number of blocks that can be covered in Python
- Program to find number of square submatrices with 1 in python
- Python Program for Find largest prime factor of a number
- Area of the Largest square that can be inscribed in an ellipse in C++
- Find the largest number that can be formed with the given digits in C++
- Program to find total area covered by two rectangles in Python
- Python Program to Find the Second Largest Number in a List Using Bubble Sort
- Program to find the sum of largest K sublist in Python
- Java program to find the largest number in an array
- Program to find probability that any proper divisor of n would be an even perfect square number in Python