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
4d
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...
Top SAP Associate Software Engineer interview questions & answers
Popular interview questions of Associate Software Engineer
Top HR questions asked in SAP Associate Software Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app