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!
Select
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
SAP Associate Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits