Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Perfect Rectangle

XPChallenge Points: 30
levelLevel: Hard

You are given a list of axis-aligned rectangles, where each rectangle is represented as
[x1, y1, x2, y2], describing its bottom-left corner (x1, y1) and top-right corner (x2, y2).

Your task is to determine whether all these rectangles fit together perfectly to form one single large rectangle, without any gaps or overlapping regions.

If they combine to make an exact rectangular region, return true; otherwise return false.

Example 1:

Input: rectangles = [[0,0,2,2],[2,0,3,1],[2,1,3,2],[0,2,1,3],[1,2,3,3]]

Output: true

Explanation:

All small rectangles join to form one clean 3×3 rectangle.

Example 2:

Input: rectangles = [[0,0,1,2],[0,2,1,3],[1,0,3,2]]

Output: false

Explanation:

There is an empty region on the top-right area.

Example 3:

Input: rectangles = [[1,1,3,3],[2,2,4,4]]

Output: false

Explanation:

Overlapping happens between the two rectangles.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result