← Back to challenges

Area of Overlapping Rectangles

PythonHardalgebramathobjectsgeometry

Instructions

Create a function that returns the area of the overlap between two rectangles. The function will receive two rectangles, each with the coordinates of the lower left corner followed by the width and the height rect = [x, y, width, height].

Examples

overlapping_rectangles([ 2, 1, 3, 4 ], [ 3, 2, 2, 5 ]) ➞ 6

overlapping_rectangles([ 2, -9, 11, 5 ], [ 5, -11, 2, 9 ]) ➞ 10

overlapping_rectangles([ -8, -7, 4, 7 ],  [-5, -9, 4, 7 ]) ➞ 5

Example 1

Example 2

Example 3

Notes

  • Coordinates can be positive or negative integers.
  • Not all examples have overlaps.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.