Trains the technique from
LeetCode 223Rectangle AreaThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Two rugs lie flat on a floor, each with its sides parallel to the floor's grid lines. A survey marker sits at the origin, so a coordinate may be negative.
The first rug spans from the corner (ax1, ay1) to the opposite corner (ax2, ay2), with ax1 the smaller horizontal coordinate and ay1 the smaller vertical one. The second rug spans from (bx1, by1) to (bx2, by2) under the same rule. A rug may be folded flat, in which case one of its sides has length zero and it covers nothing.
Return the area of floor that has at least one rug over it. Floor that both rugs cover counts once. Two rugs whose edges only meet along a line, or at a single point, do not share any area.
Example 1
The first rug covers 16 units of floor and the second covers 12. The floor they share runs horizontally from 0 to 2 and vertically from 0 to 2, so 4 units are under both and are counted once: 16 + 12 - 4 = 24.
Example 2
The rugs meet along the vertical line at 2 and share no area, so the total is 4 + 4 = 8.
Example 3
The smaller rug lies entirely on top of the larger one, so the covered floor is just the larger rug's 100 units.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def compute_area(ax1: int, ay1: int, ax2: int, ay2: int, bx1: int, by1: int, bx2: int, by2: int) -> int:public int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.