955. Rectangle Area II — Coordinate Compression

HardTreesSegment TreeSweep LineCoordinate Compression

Given a list of axis-aligned rectangles, each as [x1, y1, x2, y2] (bottom-left and top-right corners), return the total area covered by their union, modulo 1,000,000,007. Overlapping regions are counted once. The input is a JSON array of rectangles.

Input: A JSON array of rectangles.

Output: Integer — the total covered area mod 1e9+7.

Examples

Example 1
Input: [[0,0,2,2],[1,0,2,3],[1,0,3,1]]
Output: 6
Explanation: Union area is 6.
Example 2
Input: [[0,0,1,1],[2,2,3,3]]
Output: 2
Explanation: Two disjoint unit squares.
Example 3
Input: [[0,0,1,1]]
Output: 1
Explanation: Single rectangle.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →