|
| 1 | +<p>You are given an integer <code>n</code> representing the dimensions of an <code>n x n</code><!-- notionvc: fa9fe4ed-dff8-4410-8196-346f2d430795 --> grid, with the origin at the bottom-left corner of the grid. You are also given a 2D array of coordinates <code>rectangles</code>, where <code>rectangles[i]</code> is in the form <code>[start<sub>x</sub>, start<sub>y</sub>, end<sub>x</sub>, end<sub>y</sub>]</code>, representing a rectangle on the grid. Each rectangle is defined as follows:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li><code>(start<sub>x</sub>, start<sub>y</sub>)</code>: The bottom-left corner of the rectangle.</li> |
| 5 | + <li><code>(end<sub>x</sub>, end<sub>y</sub>)</code>: The top-right corner of the rectangle.</li> |
| 6 | +</ul> |
| 7 | + |
| 8 | +<p><strong>Note </strong>that the rectangles do not overlap. Your task is to determine if it is possible to make <strong>either two horizontal or two vertical cuts</strong> on the grid such that:</p> |
| 9 | + |
| 10 | +<ul> |
| 11 | + <li>Each of the three resulting sections formed by the cuts contains <strong>at least</strong> one rectangle.</li> |
| 12 | + <li>Every rectangle belongs to <strong>exactly</strong> one section.</li> |
| 13 | +</ul> |
| 14 | + |
| 15 | +<p>Return <code>true</code> if such cuts can be made; otherwise, return <code>false</code>.</p> |
| 16 | + |
| 17 | +<p> </p> |
| 18 | +<p><strong class="example">Example 1:</strong></p> |
| 19 | + |
| 20 | +<div class="example-block"> |
| 21 | +<p><strong>Input:</strong> <span class="example-io">n = 5, rectangles = [[1,0,5,2],[0,2,2,4],[3,2,5,3],[0,4,4,5]]</span></p> |
| 22 | + |
| 23 | +<p><strong>Output:</strong> <span class="example-io">true</span></p> |
| 24 | + |
| 25 | +<p><strong>Explanation:</strong></p> |
| 26 | + |
| 27 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2024/10/23/tt1drawio.png" style="width: 285px; height: 280px;" /></p> |
| 28 | + |
| 29 | +<p>The grid is shown in the diagram. We can make horizontal cuts at <code>y = 2</code> and <code>y = 4</code>. Hence, output is true.</p> |
| 30 | +</div> |
| 31 | + |
| 32 | +<p><strong class="example">Example 2:</strong></p> |
| 33 | + |
| 34 | +<div class="example-block"> |
| 35 | +<p><strong>Input:</strong> <span class="example-io">n = 4, rectangles = [[0,0,1,1],[2,0,3,4],[0,2,2,3],[3,0,4,3]]</span></p> |
| 36 | + |
| 37 | +<p><strong>Output:</strong> <span class="example-io">true</span></p> |
| 38 | + |
| 39 | +<p><strong>Explanation:</strong></p> |
| 40 | + |
| 41 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2024/10/23/tc2drawio.png" style="width: 240px; height: 240px;" /></p> |
| 42 | + |
| 43 | +<p>We can make vertical cuts at <code>x = 2</code> and <code>x = 3</code>. Hence, output is true.</p> |
| 44 | +</div> |
| 45 | + |
| 46 | +<p><strong class="example">Example 3:</strong></p> |
| 47 | + |
| 48 | +<div class="example-block"> |
| 49 | +<p><strong>Input:</strong> <span class="example-io">n = 4, rectangles = [[0,2,2,4],[1,0,3,2],[2,2,3,4],[3,0,4,2],[3,2,4,4]]</span></p> |
| 50 | + |
| 51 | +<p><strong>Output:</strong> <span class="example-io">false</span></p> |
| 52 | + |
| 53 | +<p><strong>Explanation:</strong></p> |
| 54 | + |
| 55 | +<p>We cannot make two horizontal or two vertical cuts that satisfy the conditions. Hence, output is false.</p> |
| 56 | +</div> |
| 57 | + |
| 58 | +<p> </p> |
| 59 | +<p><strong>Constraints:</strong></p> |
| 60 | + |
| 61 | +<ul> |
| 62 | + <li><code>3 <= n <= 10<sup>9</sup></code></li> |
| 63 | + <li><code>3 <= rectangles.length <= 10<sup>5</sup></code></li> |
| 64 | + <li><code>0 <= rectangles[i][0] < rectangles[i][2] <= n</code></li> |
| 65 | + <li><code>0 <= rectangles[i][1] < rectangles[i][3] <= n</code></li> |
| 66 | + <li>No two rectangles overlap.</li> |
| 67 | +</ul> |
0 commit comments