Skip to main content
Back to problems
Leetcode
Medium
Geometry
Math
Circle and Rectangle Overlapping

Determine whether a circle and an axis-aligned rectangle overlap in the plane.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.

1401. Circle and Rectangle Overlapping

gfg
Problem Statement

Problem

Given a circle with center (xc,yc)(x_c, y_c) and radius rr, and an axis-aligned rectangle whose bottom-left corner is (x1,y1)(x_1, y_1) and top-right corner is (x2,y2)(x_2, y_2), determine whether the two shapes overlap.

The circle and rectangle are considered overlapping if they share at least one point. Touching the boundary counts as overlapping.

Goal

Return true if the circle intersects the rectangle, otherwise return false.

Clarification

The rectangle sides are parallel to the coordinate axes. The circle may be entirely inside the rectangle, the rectangle may be entirely inside the circle, or they may intersect partially.

Input Format

A single test case is provided as integers/coordinates describing:

  • circle center (x_c, y_c) and radius r
  • rectangle corners (x_1, y_1) and (x_2, y_2)

Output Format

Return a boolean value indicating whether the circle and rectangle overlap.

Constraints

  • The rectangle is axis-aligned.
  • Boundary contact counts as overlap.
  • Coordinates and radius fit in standard 32-bit integer ranges in typical interview settings.
Examples
Sample cases returned by the problem API.

Example 1

Input

circle = (1, 1), r = 1; rectangle = [(0, 0), (2, 2)]

Output

true

Explanation

The circle is fully inside the rectangle, so they overlap.

Example 2

Input

circle = (1, 1), r = 1; rectangle = [(3, 0), (5, 2)]

Output

false

Explanation

The closest point in the rectangle to the circle center is (3, 1), which is 2 units away from the center, greater than the radius.

Show 1 more example

Example 3

Input

circle = (0, 0), r = 5; rectangle = [(4, 4), (8, 8)]

Output

true

Explanation

The point (4, 4) lies on the circle boundary since its distance from the center is 32\sqrt{32}, which is less than 5, so the shapes overlap.

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.