Rectangle Area Calculation

Given a list of rectangles, where each rectangle is represented by an array of four integers indicating its bottom-left and top-right corners, calculate the total area covered by all rectangles on the plane.

Input

The first line of input contains an integer ‘T’ denoting the number of test cases. 
Each test case starts with an integer ‘N’ representing the number of rectangles.
The next N lines contain four integers representing the bottom left and top right coordinates of each rectangle.

Output

For each test case, return the total area covered by all the rectangles. Return the result modulo 10^9+7.

Example

Input:
Rectangles = [[0, 0, 2, 2], [1, 0, 2, 3], [1, 0, 3, 1]]
Output:
6
Explanation:

The first rectangle occupies an area of 4 units, and the second rectangle occupies 3 units, with a 3-unit overlapping area. The total area covered is 6 units.

Constraints

  • 1 <= T <= 10
  • 1 <= N <= 200
  • 0 <= x1, y1, x2, y2 <= 10^9
  • Time Limit: 1 second
AnswerBot
4mo

Calculate total area covered by a list of rectangles on a plane.

  • Iterate through each rectangle and calculate its area

  • Check for overlapping areas between rectangles

  • Sum up the total area covered by all ...read more

Help your peers!
Select
Add answer anonymously...

Popular interview questions of Software Engineer

A Software Engineer was asked Q1. Bit Set Problem Statement You are provided with a string, termed as DIGIT_PATTER...read more
A Software Engineer was asked Q2. Rectangle Area Calculation Given a list of rectangles, where each rectangle is r...read more
A Software Engineer was asked Q3. Print All Permutations of a String Given an input string STR, generate and print...read more
Grey Orange 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