1
# Runtime: 275 ms (Top 78.13%) | Memory: 14.5 MB (Top 9.38%)3
def numPoints(self, points: List[List[int]], r: int) -> int:5
def getPointsInside(i, r, n):6
# This vector stores alpha and beta and flag7
# is marked true for alpha and false for beta12
if i != j and distance[i][j] <= 2 * r:13
# acos returns the arc cosine of the complex14
# used for cosine inverse15
B = math.acos(distance[i][j] / (2 * r))17
# arg returns the phase angle of the complex21
A = math.atan2(y1 - y2, x1 - x2)27
angles.append((alpha, False))29
angles.append((beta, True))31
# angles vector is sorted and traversed33
# count maintains the number of points inside34
# the circle at certain value of theta35
# res maintains the maximum of all count49
# Returns count of maximum points that can lie50
# in a circle of radius r.51
# a dis array stores the distance between every55
distance = [[0 for _ in range(max_pts)] for _ in range(max_pts)]56
for i in range(n - 1):57
for j in range(i + 1, n):58
# abs gives the magnitude of the complex59
# number and hence the distance between63
distance[i][j] = distance[j][i] = sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)65
# This loop picks a point p67
# maximum number of points for point arr[i]69
ans = max(ans, getPointsInside(i, r, n))