#1725

Number Of Rectangles That Can Form The Largest Square

newbie · 190 · lc easy +16 · verified · 79.4% accepted · 624 likes · top 91%

Description

You are given rectangles[i] = [li, wi]. From each rectangle you can cut a square with side at most min(li, wi). Let maxLen be the largest square side achievable from any rectangle. Return the count of rectangles that can produce a square with side maxLen.

Example 1:

Input: rectangles = [[5,8],[3,9],[5,12],[16,5]]
Output: 3
Explanation: The largest squares you can get from each rectangle are of lengths [5,3,5,5].
The largest possible square is of length 5, and you can get it out of 3 rectangles.

Example 2:

Input: rectangles = [[2,3],[3,7],[4,3],[3,7]]
Output: 3

Code

1
2
3