Total Screen Area Covered by Overlapping Overlay Windows
Last updated: November 29, 2026
Quick Overview
A video call layout places axis-aligned rectangular overlays (x1, y1, x2, y2) on the screen, and they may overlap. Return the total area covered by at least one overlay.
Meta
November 29, 20260
0
0 solved
A video call layout places axis-aligned rectangular overlays (x1, y1, x2, y2) on the screen, and they may overlap. Return the total area covered by at least one overlay.
This union-of-rectangles sweep is in the style of a Meta onsite hard problem, framed around measuring how much of a Messenger video call screen is hidden by stickers, captions, and participant tiles. The interviewer looks for a sweep line over x with coordinate compression and a clear way to measure covered length in y.
What the Interviewer Expects
- Explains why inclusion-exclusion over pairs fails for three or more overlaps
- Sweeps along x with open and close events
- Maintains active y-intervals and measures their union length between events
- Mentions a segment tree with coverage counts for O(n log n)
- Uses 64-bit-safe arithmetic or a modulus if asked
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Implement the segment tree version to reach O(n log n).
- How would you return the area covered by at least two overlays?
- What if rectangles are added and removed live during the call?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of rectangles (x1, y1, x2, y2) with x1 < x2 and y1 < y2. Output: area of their union. n is at most a few hundred for a call layout, but the approach should name the path to larger n....
High-Level Design
Create two events per rectangle: open at x1 and close at x2, each carrying its y-interval. Sort events by x. Between consecutive event x positions, the set of active rectangles is constant, so the cov...