TomoLink
CompaniesAmazonData Structures & AlgorithmsPerfect Rectangle
DSA
HardArray

Perfect Rectangle

arrayhash tablemath

Problem Statement

Given an array rectangles where rectangles[i] = [x _i , y _i , a _i , b _i ] represents an axis-aligned rectangle. The bottom-left point of the rectangle is (x _i , y _i ) and the top-right point of it is (a _i , b _i ) .

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

Examples

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: true
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: false
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: false
Because two of the rectangles overlap with each other.

Constraints

1 <= rectangles.length <= 2 * 10 ^4
rectangles[i].length == 4
-10 ^5 <= x _i < a _i <= 10 ^5
-10 ^5 <= y _i < b _i <= 10 ^5
😤
Hard
Difficulty
Topic Info
ModuleDSA
CategoryArray
Sub-topicHash Table
Tags
arrayhash tablemathgeometrysweep line
Navigation
Perfect Rectangle [Hard] | Amazon Dsa | TomoLink