Total area of overlapping rectangles

Posted: 10 Nov, 2020
Difficulty: Easy

PROBLEM STATEMENT

Note:

``````1. For a rectangle, its top left and bottom right coordinates are given.

2. Coordinates of the rectangles are integer values.

3. Edges of the given rectangles will always be parallel to the X and Y coordinate axes of the cartesian plane.

4. It is guaranteed that both the rectangles will have at least a unit area.
``````
Input Format:
``````The first line of the input contains an integer 'T' denoting the number of test cases.

The first line of each test case contains 4 space-separated integer values 'x1', 'y1', 'x2', 'y2' denoting the top left ('x1', 'y1') and bottom-right ('x2', 'y2') coordinates of the first rectangle.

The second line of each test case contains 4 space-separated integer values 'x3', 'y3', 'x4', 'y4' denoting the top left ('x3', 'y3') and bottom-right ('x4', 'y4') coordinates of the second rectangle.
``````
Output Format:
``````For each test case, return an integer denoting the net area of two rectangles.
``````
Note:
``````You do not need to print anything, it has already been taken care of. Just implement the given function.
``````
Constraints:
``````1 <= T <= 10^5
-10^9 <= x1, y1, x2, y2 <= 10^9
x1 < x2, x3 < x4
y1 > y2, y3 > y4

Time Limit: 1sec
``````