391. Perfect Rectangle

Hard

764

112

Given an array `rectangles`

where `rectangles[i] = [x`

represents an axis-aligned rectangle. The bottom-left point of the rectangle is _{i}, y_{i}, a_{i}, b_{i}]`(x`

and the top-right point of it is _{i}, y_{i})`(a`

._{i}, b_{i})

Return `true`

*if all the rectangles together form an exact cover of a rectangular region*.

**Example 1:**

Input:rectangles = [[1,1,3,3],[3,1,4,2],[3,2,4,4],[1,3,2,4],[2,3,3,4]]Output:trueExplanation:All 5 rectangles together form an exact cover of a rectangular region.

**Example 2:**

Input:rectangles = [[1,1,2,3],[1,3,2,4],[3,1,4,2],[3,2,4,4]]Output:falseExplanation:Because there is a gap between the two rectangular regions.

**Example 3:**

Input:rectangles = [[1,1,3,3],[3,1,4,2],[1,3,2,4],[2,2,4,4]]Output:falseExplanation:Because two of the rectangles overlap with each other.

**Constraints:**

`1 <= rectangles.length <= 2 * 10`

^{4}`rectangles[i].length == 4`

`-10`

^{5}<= x_{i}, y_{i}, a_{i}, b_{i}<= 10^{5}

Accepted

38.9K

Submissions

118.5K

Acceptance Rate

32.8%

Seen this question in a real interview before?

1/4

Yes

No

Discussion (0)

Related Topics

Copyright ©️ 2023 LeetCode All rights reserved