Union Area of Rectangles
You are given axis-aligned rectangles in rectangles, where rectangles[i] = [x1, y1, x2, y2] describes the half-open region from bottom-left corner (x1, y1) to top-right corner (x2, y2).
Return the total area covered by at least one rectangle. Overlapping regions count only once.
Toggle rectangles in the demo to see which unit cells belong to the union and how overlap is counted once.
rectangles = [[1,1,4,3],[2,2,5,4]]
10
rectangles = [[0,0,2,2],[2,0,4,2]]
8
rectangles = [[0,0,3,3],[1,1,2,2]]
9
- 1 <= rectangles.length <= 200
- rectangles[i].length == 4
- 0 <= x1 < x2 <= 10^4
- 0 <= y1 < y2 <= 10^4