You are given a 2D integer array rectangles where rectangles[i] = [width, height] gives the dimensions of the i-th rectangle.
The largest square that fits inside a rectangle has a side length equal to the minimum of its width and height. Define squareArea(i) as the area of that largest square for rectangle i.
Return the maximum value of squareArea(i) over all rectangles, together with the number of rectangles that reach that maximum, packed as [maxArea, count]. The count is part of the answer even when only one rectangle reaches the maximum.
Function Signature
def maximum_embeddable_square_area(rectangles: list[list[int]]) -> list[int]:
...
Rules
-
Each rectangle is a list
[width, height]
. Which of the two values is the width does not matter for the square.
-
Return a list of exactly two integers,
[maxArea, count]
, where
count
is at least 1.
Constraints
-
1 <= len(rectangles) <= 10^5
-
len(rectangles[i]) == 2
-
1 <= width, height <= 10^9
Examples
Input: rectangles = [[5, 8], [3, 9], [7, 7], [10, 2]]
Output: [49, 1]
The square sides are 5, 3, 7 and 2, so the areas are 25, 9, 49 and 4. Only the 7 by 7 rectangle reaches 49.
Input: rectangles = [[2, 3], [4, 4], [6, 1], [4, 5]]
Output: [16, 2]
The sides are 2, 4, 1 and 4, giving areas 4, 16, 1 and 16. Two rectangles reach the maximum of 16.
Input: rectangles = [[6, 10], [10, 6], [6, 6]]
Output: [36, 3]
All three rectangles have a shorter side of 6, so each holds a 6 by 6 square of area 36, and the count is 3.