Back to September Back to Year 2026
MEDIUM 19 Sep 2026 View on LeetCode

1401. Circle and Rectangle Overlapping

</> Solution

/**
 * Problem: LeetCode 1401 - Circle and Rectangle Overlapping
 * Difficulty: Medium
 * Language: Java
 * Author: CodeByTushu
 */
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(1)

SPACE COMPLEXITY

O(1)

TOPICS

Geometry Math