Rectangle union area

Write codeHard40 minGoogle and Citadel style

Your task

Given a list of axis-aligned rectangles each as [x1, y1, x2, y2] (lower-left and upper-right corners, x1<x2, y1<y2), compute the total area covered by their union. Overlapping area is counted once. Use coordinate compression plus a sweep so the answer is exact. Return the area modulo 1000000007 (the raw union area can be large). There are up to 200 rectangles and coordinates fit in 32-bit ints.

Examples

rectangle_union_area(rectangles: list[list[int]]) -> int
Example 1
Inputrectangle_union_area([[0, 0, 2, 2], [1, 1, 3, 3]])
Output7