|
| 1 | +3047\. Find the Largest Area of Square Inside Two Rectangles |
| 2 | + |
| 3 | +Medium |
| 4 | + |
| 5 | +There exist `n` rectangles in a 2D plane. You are given two **0-indexed** 2D integer arrays `bottomLeft` and `topRight`, both of size `n x 2`, where `bottomLeft[i]` and `topRight[i]` represent the **bottom-left** and **top-right** coordinates of the <code>i<sup>th</sup></code> rectangle respectively. |
| 6 | + |
| 7 | +You can select a region formed from the **intersection** of two of the given rectangles. You need to find the **largest** area of a **square** that can fit **inside** this region if you select the region optimally. |
| 8 | + |
| 9 | +Return _the **largest** possible area of a square, or_ `0` _if there **do not** exist any intersecting regions between the rectangles_. |
| 10 | + |
| 11 | +**Example 1:** |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +**Input:** bottomLeft = [[1,1],[2,2],[3,1]], topRight = [[3,3],[4,4],[6,6]] |
| 16 | + |
| 17 | +**Output:** 1 |
| 18 | + |
| 19 | +**Explanation:** A square with side length 1 can fit inside either the intersecting region of rectangle 0 and rectangle 1, or the intersecting region of rectangle 1 and rectangle 2. Hence the largest area is side \* side which is 1 \* 1 == 1. |
| 20 | + |
| 21 | +It can be shown that a square with a greater side length can not fit inside any intersecting region. |
| 22 | + |
| 23 | +**Example 2:** |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +**Input:** bottomLeft = [[1,1],[2,2],[1,2]], topRight = [[3,3],[4,4],[3,4]] |
| 28 | + |
| 29 | +**Output:** 1 |
| 30 | + |
| 31 | +**Explanation:** A square with side length 1 can fit inside either the intersecting region of rectangle 0 and rectangle 1, the intersecting region of rectangle 1 and rectangle 2, or the intersection region of all 3 rectangles. Hence the largest area is side \* side which is 1 \* 1 == 1. |
| 32 | + |
| 33 | +It can be shown that a square with a greater side length can not fit inside any intersecting region. Note that the region can be formed by the intersection of more than 2 rectangles. |
| 34 | + |
| 35 | +**Example 3:** |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +**Input:** bottomLeft = [[1,1],[3,3],[3,1]], topRight = [[2,2],[4,4],[4,2]] |
| 40 | + |
| 41 | +**Output:** 0 |
| 42 | + |
| 43 | +**Explanation:** No pair of rectangles intersect, hence, we return 0. |
| 44 | + |
| 45 | +**Constraints:** |
| 46 | + |
| 47 | +* `n == bottomLeft.length == topRight.length` |
| 48 | +* <code>2 <= n <= 10<sup>3</sup></code> |
| 49 | +* `bottomLeft[i].length == topRight[i].length == 2` |
| 50 | +* <code>1 <= bottomLeft[i][0], bottomLeft[i][1] <= 10<sup>7</sup></code> |
| 51 | +* <code>1 <= topRight[i][0], topRight[i][1] <= 10<sup>7</sup></code> |
| 52 | +* `bottomLeft[i][0] < topRight[i][0]` |
| 53 | +* `bottomLeft[i][1] < topRight[i][1]` |
0 commit comments