Description
Given an array of rectangles where rectangles[i] = [li, wi], return the number of rectangles that can form the largest possible square. A rectangle can form a square of side min(li, wi).
Examples
rectangles = [[5,8],[3,9],[5,12],[16,5]]3Max square side 5, 3 rectangles.
rectangles = [[4,6],[2,8],[3,4],[4,7],[4,9]]3The largest possible square side length is 4. A square with side 4 can be formed from rectangles [4,6], [4,7], and [4,9] since each has at least one dimension >= 4. Rectangle [2,8] has max dimension 8 >= 4 but min dimension 2 < 4, so it can form the square. Rectangle [3,4] also works. Total: 4 rectangles can form squares of side 4.
rectangles = [[1,1],[2,2],[3,3]]1The largest possible square side length is 3 (from rectangle [3,3]). Only the rectangle [3,3] can form a square with side length 3, since the other rectangles [1,1] and [2,2] are too small. Therefore, only 1 rectangle can form the largest possible square.
Constraints
- •
1 ≤ rectangles.length ≤ 1000