Perfect Rectangle

Given an array rectangles where rectangles[i] = [xi, yi, ai, bi] represents an axis-aligned rectangle. The bottom-left point of the rectangle is (xi, yi) and the top-right point of it is (ai, bi).

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

Example 1
Inputrectangles = [[1,1,3,3],[3,1,4,2],[3,2,4,4],[1,3,2,4],[2,3,3,4]]
Outputtrue
All 5 rectangles together form an exact cover of a rectangular region.
Example 2
Inputrectangles = [[1,1,2,3],[1,3,2,4],[3,1,4,2],[3,2,4,4]]
Outputfalse
There is a gap between the two rectangular regions.

Constraints

  • 1 <= rectangles.length <= 2 * 10^4
  • rectangles[i].length == 4
  • -10^5 <= xi < ai <= 10^5
  • -10^5 <= yi < bi <= 10^5

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate