Rectangle union area
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.
Implement
rectangle_union_area(rectangles: list[list[int]]) → intExamples
in
[[[0,0,2,2],[1,1,3,3]]]out7What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 40 min
solution.py
InputExpectedGot
[[[0,0,2,2],[1,1,3,3]]]7not run yetsample