You are given a circle represented as (radius, xCenter, yCenter) and an axis-aligned rectangle represented as (x1, y1, x2, y2), where (x1, y1) are the coordinates of the bottom-left corner, and (x2, y2) are the coordinates of the top-right corner of the rectangle.

Return true if the circle and rectangle are overlapped otherwise return false. In other words, check if there is any point (xi, yi) that belongs to the circle and the rectangle at the same time.

&nbsp;
Example 1:

Input: radius = 1, xCenter = 0, yCenter = 0, x1 = 1, y1 = -1, x2 = 3, y2 = 1
Output: true
Explanation: Circle and rectangle share the point (1,0).


Example 2:

Input: radius = 1, xCenter = 1, yCenter = 1, x1 = 1, y1 = -3, x2 = 2, y2 = -1
Output: false


Example 3:

Input: radius = 1, xCenter = 0, yCenter = 0, x1 = -1, y1 = 0, x2 = 0, y2 = 1
Output: true


&nbsp;
Constraints:


	1 &lt;= radius &lt;= 2000
	-104 &lt;= xCenter, yCenter &lt;= 104
	-104 &lt;= x1 &lt; x2 &lt;= 104
	-104 &lt;= y1 &lt; y2 &lt;= 104


class Solution:
    def checkOverlap(self, radius: int, xCenter: int, yCenter: int, x1: int, y1: int, x2: int, y2: int) -> bool:
        
        def find(a1, a2, aCenter):
            if a1 <= aCenter and aCenter <= a2:
                return 0 
            elif a1 > aCenter:
                return  a1 - aCenter
            else:
                return aCenter - a2

        return (find(x1, x2, xCenter))**2 + (find(y1, y2, yCenter))**2 <= radius**2 
	```
class Solution
{
    public boolean checkOverlap(int radius, int xCenter, int yCenter, int x1, int y1, int x2, int y2)
    {
        return Math.pow(Math.max(x1,Math.min(x2,xCenter))-xCenter,2)
            + Math.pow(Math.max(y1,Math.min(y2,yCenter))-yCenter,2) <= radius*radius;
    }
}
class Solution {
public:
    bool checkOverlap(int radius, int xCenter, int yCenter, int x1, int y1, int x2, int y2) {
        //nearest_x = x1 when xCenter<x1<x2 (OR) x2 when x1<x2<xCenter (OR) xCenter when x1<xCenter<x2
        int nearest_x = (xCenter < x1) ? x1 : (xCenter > x2) ? x2 : xCenter;
        //same logic for nearest_y as in nearest_x
        int nearest_y = (yCenter < y1) ? y1 : (yCenter > y2) ? y2 : yCenter;
        int dist_x = xCenter - nearest_x, dist_y = yCenter - nearest_y;
        return dist_x * dist_x + dist_y * dist_y <= radius * radius;
    }
};
var checkOverlap = function(radius, xCenter, yCenter, x1, y1, x2, y2) {
    const closestX = clamp(xCenter, x1, x2);
    const closestY = clamp(yCenter, y1, y2);
    
    const dist = (xCenter - closestX)**2 + (yCenter - closestY)**2;
    
    return dist <= radius * radius ? true : false;
    
    
    function clamp(val, min, max) {
        if (val < min) return min;
        if (max < val) return max;
        return val;
    }
};
Circle and Rectangle Overlapping