Skip to main content
LeetCode 391, Hard. Topics: Array, Hash Table, Math, Geometry, Sweep Line. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 43 parametrized pytest cases, and a playground notebook:

Problem

Given an array rectangles where rectangles[i] = [x<sub>i</sub>, y<sub>i</sub>, a<sub>i</sub>, b<sub>i</sub>] represents an axis-aligned rectangle. The bottom-left point of the rectangle is (x<sub>i</sub>, y<sub>i</sub>) and the top-right point of it is (a<sub>i</sub>, b<sub>i</sub>). Return true if all the rectangles together form an exact cover of a rectangular region.

Examples

Example 1
Example 2
Example 3

Constraints

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

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026