2daysbeforeinterview
Home1Companies2Problems3Experiences4Compensation5Assistant

Spaces

Saved work

Your prep

Notes6Bookmarks7Submissions

Community

Leaderboard8Send feedback
Contribute9
2daysbeforeinterview
2daysbeforeinterview

Straight from the interview room.

Browse

  • Companies
  • Problems
  • Experiences
  • Compensation
  • Leaderboard
  • Pricing

Contribute

  • Add a question
  • Share an experience
  • Report compensation
  • Committed Contributor
  • Send feedback

About

  • About 2daysbeforeinterview
  • Contact
  • Privacy
  • Terms
  • Refunds
  • Delivery

© 2026 2daysbeforeinterview

  • Instagram(opens in a new tab)
  • YouTube(opens in a new tab)
  • X (Twitter)(opens in a new tab)
  • help@2daysbeforeinterview.com
HomeCompaniesProblems
Keep holding ⌥Alt and press a number · ? for every shortcut
Back to LiciousFunction: All functionsEngineeringDataMachine learningProductDesignQuality assuranceBusiness
Home1Companies2Problems3Experiences4Compensation5Assistant

Spaces

Saved work

Your prep

Notes6Bookmarks7Submissions

Community

Leaderboard8Send feedback
Back to Licious
DSA
1 reportlast asked …
Licious

Count Point Clusters Within a Radius

You are given an array points, where points[i] = [x, y] is a point on a plane, and an integer radius. Two points are linked when the Euclidean distance between them is at most radius.

Points form clusters by chaining. A point joins a cluster when it is linked to any point already in it, and a cluster stops growing once no outside point is linked to any of its members. So two points far apart still share a cluster if a path of linked points connects them. A point with no links is a cluster on its own.

Return the number of clusters.

Example 1

Input:  points = [[0,0],[3,4],[10,0],[13,4]], radius = 5
Output: 2

[0,0] and [3,4] are exactly 5 apart, and "at most radius" includes it, so they link. [10,0] and [13,4] link the same way. The closest pair across the two, [3,4] and [10,0], is about 8.06 apart.

Example 2

Input:  points = [[0,0],[8,0],[4,0],[20,20]], radius = 4
Output: 2

[0,0] and [8,0] are 8 apart, but [4,0] is 4 from each, so all three chain into one cluster. Scanning in order and only comparing a point with the clusters seen so far gives 3: [8,0] would start its own cluster before [4,0] arrives to join them. [20,20] is alone.

Example 3

Input:  points = [[1,1],[1,1],[2,2]], radius = 0
Output: 2

The two copies of [1,1] are 0 apart, so they link even with radius = 0. [2,2] is a cluster on its own.

Constraints

  • 1 <= points.length <= 1000
  • points[i].length == 2
  • -10^4 <= x, y <= 10^4
  • 0 <= radius <= 3 * 10^4
  • Points may repeat.

Hints

0/3

Domains

Backend
asked May 2021Report
Discussion
Related questions
Asked atLicious
My notes
Practice
EditorialLocked
Community solutions
Learning resources(3)
Licious
Licious