Problem: Total Area of Overlapping Rectangles
You are given two rectangles situated on a 2-D coordinate plane, which may overlap. Your task is to compute the total area covered by these rectangles.
Input:
The first line of input holds an integer 'T', indicating the number of test cases.
For each test case:
First line: Four integers 'x1', 'y1', 'x2', 'y2' - top-left and bottom-right coordinates of the first rectangle.
Second line: Four integers 'x3', 'y3', 'x4', 'y4' - top-left and bottom-right coordinates of the second rectangle.
Output:
Return an integer for each test case, representing the total area covered by the two rectangles.
Example:
Assuming rectangle coordinates and scenarios are illustrated with examples, as depicted in accompanying diagrams (not displayed here).
Constraints:
1 ≤ T ≤ 10^5
-10^9 ≤ x1, y1, x2, y2 ≤ 10^9
x1 < x2, x3 < x4
y1 > y2, y3 > y4
- Time Limit: 1 second
Note:
Edges of rectangles are aligned parallel to the X and Y axes.

AnswerBot
4mo
Calculate total area covered by two overlapping rectangles on a 2-D plane.
Calculate the area of each rectangle separately using the given coordinates.
Find the overlapping region by determining the int...read more
Help your peers!
Add answer anonymously...
SAP Associate Software Engineer interview questions & answers
An Associate Software Engineer was asked Q. Longest common subsequence
An Associate Software Engineer was asked Q. All Prime Numbers Less Than or Equal to N Given a positive integer N, your task ...read more
An Associate Software Engineer was asked Q. Problem: Total Area of Overlapping Rectangles You are given two rectangles situa...read more
Popular interview questions of Associate Software Engineer
An Associate Software Engineer was asked Q1. Longest common subsequence
An Associate Software Engineer was asked Q2. All Prime Numbers Less Than or Equal to N Given a positive integer N, your task ...read more
An Associate Software Engineer was asked Q3. Problem: Total Area of Overlapping Rectangles You are given two rectangles situa...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

