Rectangle Area

Medium · Math & Number Theory · about 15 minutes

Asked at Google, Amazon, Microsoft, Bloomberg.

Two rectangles have sides parallel to the axes. The first has lower-left corner (ax1, ay1) and upper-right corner (ax2, ay2); the second has corners (bx1, by1) and (bx2, by2). Return the area of the region covered by at least one of them (overlap counted once).