Determine whether two axis-aligned rectangles overlap with positive area.
Problem
You are given two axis-aligned rectangles in the 2D plane. Each rectangle is described by the coordinates of its bottom-left corner and top-right corner.
Return whether the two rectangles overlap with positive area. Touching at an edge or a corner does not count as overlap.
A rectangle is represented as [x1, y1, x2, y2] where:
(x1, y1)is the bottom-left corner(x2, y2)is the top-right cornerx1 < x2andy1 < y2
Key idea
Two axis-aligned rectangles overlap if and only if they overlap on both the x-axis and the y-axis with a strictly positive intersection length.
Input Format
- Two rectangles
rec1andrec2 - Each rectangle is an array of four integers:
[x1, y1, x2, y2]
Output Format
- Return
trueif the rectangles overlap with positive area - Otherwise return
false
Constraints
rec1.length == rec2.length == 4x1 < x2andy1 < y2for each rectangle- Coordinates are integers
Example 1
Input
rec1 = [0,0,2,2], rec2 = [1,1,3,3]
Output
true
Explanation
The rectangles share a 1x1 area in the middle.
Example 2
Input
rec1 = [0,0,1,1], rec2 = [1,1,2,2]
Output
false
Explanation
They only meet at one corner, so the overlap area is zero.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.