Radius Clusters
Asked at Google
Reported by the problem's creator, not verified
You are given points, a list of [x, y] integer coordinates, and an integer radius.
python def count_clusters(points: list[list[int]], radius: int) -> int: raise NotImplementedError
Two points are linked when the straight-line distance between them is at most radius. Linking is transitive: a cluster is a group of points where each point is linked to another point of the group, directly or through a chain of linked points, and no point is linked to a point outside it.
Return the number of clusters. A point with no links is a cluster of one. Points with the same coordinates are separate points at distance 0 from each other, so they are always in the same cluster.
Examples
Example 1
Input: points =
[[0,0],[1,0],[5,5],[6,5],[20,20]], radius =1Output:
3Explanation:
[0, 0]and[1, 0]are 1 apart, and[5, 5]and[6, 5]are 1 apart.[20, 20]is far from everything, so it forms a cluster of its own: 3 clusters.Example 2
Input: points =
[[0,0],[3,0],[6,0],[9,0]], radius =3Output:
1Explanation: Each point is 3 from the next, so a chain joins all four even though
[0, 0]and[9, 0]are 9 apart: 1 cluster.