The Rectangle Area problem gives you two axis-aligned rectangles (each defined by bottom-left and top-right corners) and asks for the total area covered by both. This includes the overlap area counted only once. This medium coding problem uses geometric intersection computation. The math and geometry interview pattern is demonstrated.
Apple, Microsoft, Meta, Amazon, and Google ask this to test 2D geometry: area = area1 + area2 - intersection_area. Computing the intersection requires finding the overlapping x-range and y-range. It validates the ability to handle 2D rectangle geometry cleanly.
Area union formula + intersection computation. Total = area1 + area2 - intersection. Intersection width = max(0, min(x2,x4) - max(x1,x3)). Intersection height = max(0, min(y2,y4) - max(y1,y3)). Intersection area = width × height.
Rect1: (0,0)→(2,2). Area1=4. Rect2: (1,1)→(3,3). Area2=4. Intersection: width=min(2,3)-max(0,1)=2-1=1. Height=min(2,3)-max(0,1)=1. Intersection area=1. Total = 4+4-1 = 7.
No overlap: Rect2=(3,3)→(5,5). Width=max(0,min(2,5)-max(0,3))=max(0,-1)=0. Intersection=0. Total=4+4=8.
Rectangle Area is a clean geometry problem. Memorize the formula: total = A1 + A2 - intersection, where intersection = max(0, min_right - max_left) × max(0, min_top - max_bottom). The max(0, ...) handles the no-overlap case automatically. Practice with different rectangle configurations to build intuition for overlap edge cases.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Circle and Rectangle Overlapping | Medium | Solve | |
| Valid Square | Medium | Solve | |
| Rectangle Overlap | Easy | Solve | |
| Minimum Cuts to Divide a Circle | Easy | Solve | |
| Mirror Reflection | Medium | Solve |