Back to Month
MEDIUM 19 Sep 2026 View on LeetCode

1401. Circle and Rectangle Overlapping

</> Solution

class Solution {
    public boolean checkOverlap(int radius, int xCenter, int yCenter, int x1, int y1, int x2, int y2) {
       int closestX = clamp(xCenter, x1, x2);
        int closestY = clamp(yCenter, y1, y2);
        long dx = xCenter - closestX;
        long dy = yCenter - closestY;
        return dx * dx + dy * dy <= (long) radius * radius;
    }
    private int clamp(int val, int min, int max) {
        return Math.max(min, Math.min(max, val)); 
    }
}

TIME COMPLEXITY

O(n)

SPACE COMPLEXITY

O(1)

TOPICS

Coordinate Geometry Geometry Math