Reported October 2026
DocuSignmath

Union Area of Two Rectangles

Reported by candidates from DocuSign's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live DocuSign OA. Under 2s to a working solution.
Founder's read

DocuSign reported this one in October 2026, and it looks harder than it is. Two rectangles, find the area covered by at least one. Under the geometry it's inclusion-exclusion: area A plus area B minus the overlap. If you have an OA invite for this week, the whole job is computing that overlap without tripping on edge cases. Coordinates go up to 10^9, so the math gets big fast. If you blank mid-assessment, StealthCoder runs invisibly on your desktop and can hand you the formula in real time. You probably won't need it, though.

The problem

Two axis-aligned rectangles are described by their bottom-left and top-right corners: (ax1, ay1), (ax2, ay2) and (bx1, by1), (bx2, by2).
Return the total area covered by at least one rectangle.

Function
rectangleUnionArea(ax1: int, ay1: int, ax2: int, ay2: int, bx1: int, by1: int, bx2: int, by2: int) → long

Examples
Example 1
ax1 = -3
ay1 = 0
ax2 = 3
ay2 = 4
bx1 = 0
by1 = -1
bx2 = 9
by2 = 2
return = 45
The rectangle areas are 24 and 27, and their overlap area is 6, giving 45.
Example 2
ax1 = 0
ay1 = 0
ax2 = 2
ay2 = 2
bx1 = 2
by1 = 0
bx2 = 4
by2 = 2
return = 8
The rectangles touch at an edge but have zero overlap area.

Constraints
-10^9 <= ax1 < ax2 <= 10^9 and -10^9 <= ay1 < ay2 <= 10^9.
The same strict corner ordering holds for rectangle B.
The answer fits in a signed 64-bit integer.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that overlap on each axis is independent. Width of overlap is max(0, min(ax2, bx2) - max(ax1, bx1)). Height is max(0, min(ay2, by2) - max(ay1, by1)). Multiply them for the intersection area. Answer is areaA + areaB - intersection. The common pitfall is overflow. Side lengths reach 2*10^9, which blows past a 32-bit int, and the product reaches 4*10^18. Cast to long before you subtract or multiply, not after. The second pitfall is forgetting the max(0,...) clamp, which gives negative overlap for disjoint rectangles and inflates the answer. Example 2 covers the touching case: overlap width is 0, so the area is 8. Run both examples by hand before submitting. If the clamp or the cast slips your mind under pressure, StealthCoder is the hedge on the live OA.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Union Area of Two Rectangles cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as rectangle area. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass DocuSign's OA.

DocuSign reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Union Area of Two Rectangles FAQ

How hard is the Union Area of Two Rectangles problem really?+

Easy on logic, easy to botch on details. The formula is three lines. Most failures come from integer overflow and a missing clamp on negative overlap. If you handle those two, it passes. Budget your time for edge cases, not the algorithm.

What's the trick to this DocuSign OA question?+

Treat x and y independently. Overlap width is min of the right edges minus max of the left edges, clamped at zero. Same for height. Union equals area A plus area B minus width times height of the overlap.

Why does my answer go wrong on large inputs?+

Overflow. Coordinates reach 10^9 in magnitude, so one side can be 2*10^9, which doesn't fit in a 32-bit int. Convert the coordinates to 64-bit before subtracting and multiplying. Casting only the final product is too late.

How should I handle rectangles that only touch or don't overlap?+

Clamp each overlap dimension with max(0, value). Touching edges give zero width or height, so the intersection is zero. Disjoint rectangles give negative raw values, and without the clamp you'd add area instead of ignoring it. Example 2 tests exactly this.

How do I prepare for this in 48 hours?+

Write the function once from memory, then test it on both examples plus a fully nested case and a fully disjoint case. That takes about 15 minutes. Spend the rest of your time on other geometry and array problems, since this one is formula-driven.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with DocuSign.

OA at DocuSign?
Invisible during screen share
Get it