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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
Sweep line
Coordinate compression
Interval union
Segment tree
Geometry
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported