Skip to main content
LeetCode 223, Medium. Topics: Math, Geometry. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 18 parametrized pytest cases, and a playground notebook:

Problem

Given the coordinates of two rectilinear rectangles in a 2D plane, return the total area covered by the two rectangles. The first rectangle is defined by its bottom-left corner (ax1, ay1) and its top-right corner (ax2, ay2). The second rectangle is defined by its bottom-left corner (bx1, by1) and its top-right corner (bx2, by2).

Examples

Example 1

Constraints

  • -10^4 <= ax1 <= ax2 <= 10^4
  • -10^4 <= ay1 <= ay2 <= 10^4
  • -10^4 <= bx1 <= bx2 <= 10^4
  • -10^4 <= by1 <= by2 <= 10^4

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026