Find the total area covered by two rectilinear rectangles in a 2D plane.
Each rectangle is defined to bottom left corner and top right corner as shown in the figure.
Assume that "total" is never beyond the maximum possible value of int.
Credits:
Special @mithmatt for adding this problem, creating the above image and all test cases
Class Solution {public
:
int computearea (int A, int B, int C, int D, int E, int F, int G, int H) {
int val = ( C-A) * (d-b) + (G-E) * (h-f);
if (E > C | | G < A | | F > D | | H < B) {return
val;
}
Val-= (min (c,g)-Max (A,e)) * (min (d,h)-Max (b,f));
return val;
}
;
Class Solution {public
:
int computearea (int A, int B, int C, int D, int E, int F, int G, int H) {
int res = ( D-b) * (c-a) + (h-f) * (G-E);
int A1 = max (A, E), B1 = Max (B, F), C1 = min (C, G), D1 = min (D, H);
if (D1 <= B1 | | C1 <= A1) return res;
return Res-(D1-B1) * (C1-A1);
}
;