Area of Two Rectangles
Each rectangle is [x1, y1, x2, y2] (bottom left and top right corners, sides parallel to the axes). Return the total area covered by the two rectangles together, counting any shared region only once.
Example 1
r1 [0,0,3,3]
r2 [2,2,4,4]
returns 12
9 + 4 - 1 = 12.
Constraints
- Each rectangle has
x1 < x2andy1 < y2 - Coordinates are between -20 and 20
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.