Skip to main content
Back to problems
Leetcode
Medium
Geometry
Math
836. Rectangle Overlap

Determine whether two axis-aligned rectangles overlap with positive area.

Acceptance 0%
Problem Statement

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 corner
  • x1 < x2 and y1 < 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 rec1 and rec2
  • Each rectangle is an array of four integers: [x1, y1, x2, y2]

Output Format

  • Return true if the rectangles overlap with positive area
  • Otherwise return false

Constraints

  • rec1.length == rec2.length == 4
  • x1 < x2 and y1 < y2 for each rectangle
  • Coordinates are integers
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.