Given the coordinates of two rectilinear rectangles in a 2D plane, return the total area covered by the two rectangles.

The first rectangle is defined by its bottom-left corner (ax1, ay1) and its top-right corner (ax2, ay2).

The second rectangle is defined by its bottom-left corner (bx1, by1) and its top-right corner (bx2, by2).

&nbsp;
Example 1:

Input: ax1 = -3, ay1 = 0, ax2 = 3, ay2 = 4, bx1 = 0, by1 = -1, bx2 = 9, by2 = 2
Output: 45


Example 2:

Input: ax1 = -2, ay1 = -2, ax2 = 2, ay2 = 2, bx1 = -2, by1 = -2, bx2 = 2, by2 = 2
Output: 16


&nbsp;
Constraints:


	-104 &lt;= ax1 &lt;= ax2 &lt;= 104
	-104 &lt;= ay1 &lt;= ay2 &lt;= 104
	-104 &lt;= bx1 &lt;= bx2 &lt;= 104
	-104 &lt;= by1 &lt;= by2 &lt;= 104


class Solution:
    def computeArea(self, ax1: int, ay1: int, ax2: int, ay2: int, bx1: int, by1: int, bx2: int, by2: int) -> int:
        def segment(ax1,ax2,bx1,bx2):
            return min(ax2,bx2) - max(ax1, bx1) if max(ax1, bx1) < min(ax2, bx2) else 0
        return (ax2-ax1)*(ay2-ay1) + (bx2-bx1)*(by2-by1) - segment(ax1,ax2,bx1,bx2)*segment(ay1,ay2,by1,by2)
class Solution {
    public int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {
        int x1 = Math.max(ax1,bx1);
        int y1 = Math.max(ay1,by1);
        int x2 = Math.min(ax2,bx2);
        int y2 = Math.min(ay2,by2);

        int area = 0;
        int R1 = (ax2-ax1)*(ay2-ay1);
        int R2 = (bx2-bx1)*(by2-by1);
        area = R1 + R2;

        if(x2 > x1 && y2 > y1){
            int overlap = (x2-x1)*(y2-y1);
            area = area - overlap;
        }

        return area;
    }
}
class Solution {
public:
    int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {
        int rec1=abs(ax2-ax1)*abs(ay2-ay1); //Area(Rectangle 1)
        int rec2=abs(bx2-bx1)*abs(by2-by1); //Area(Rectangle 2)

        //As explained above, if intervals overlap, max(x1,x3) < min(x2,x4) and overlapped interval
        //is ( max(x1,x3) , min(x2,x4) ).

        int ox1=(max(ax1,bx1)-min(ax2,bx2)); //if ox1 is negative, abs(ox1) is the length of overlapped rectangle, else rectangles do not overlap.
        int oy1=(max(ay1,by1)-min(ay2,by2)); //breadth of overlapped rectangle

        int rec3=0; //if rectangles do not overlap, area of overlapped rectangle is zero.
        if(ox1<0&&oy1<0) //if both ox1 and oy2 are negative, two rectangles overlap.
            rec3=ox1*oy1;
        return rec1+rec2-rec3; //Area(Rectangle 1) + Area(Rectangle 2) - Area(Overlapped triangle)
    }
};
var computeArea = function(ax1, ay1, ax2, ay2, bx1, by1, bx2, by2) {
    let area1 = (ax2-ax1)*(ay2-ay1)
    let area2 = (bx2-bx1)*(by2-by1)
    let overlap = (by1>ay2 || by2<ay1 || bx1>ax2 || bx2<ax1) ? 0 : Math.abs((Math.min(ax2,bx2) - Math.max(ax1, bx1))*(Math.min(ay2,by2) - Math.max(ay1, by1)))
    
    return area1 + area2 - overlap
};
Rectangle Area