Ctrl K

Water as Many Plants as Possible

Hard
A large field has n plants; plants[i] = [x, y] gives the position of plant i. A sprinkler waters a circle of radius radius centered where it is placed, and the center can be any point of the plane, not necessarily one with integer coordinates. A plant counts as watered if it lies inside the circle or on its edge. Return the largest number of plants a single sprinkler can water.
Example 1
plants=[[0, 0], [4, 0], [2, 1], [10, 10]], radius=2 → 3

A sprinkler at (2, 0) reaches (0, 0) and (4, 0), which sit exactly on the edge, and (2, 1). The plant at (10, 10) is out of reach.

Example 2
plants=[[1, 1], [5, 5]], radius=1 → 1

The plants are more than two radii apart, so they cannot both be watered.

Constraints
  • 1 ≤ len(plants) ≤ 100
  • len(plants[i]) = 2
  • -10⁴ ≤ x, y ≤ 10⁴
  • All plants are at distinct points
  • 1 ≤ radius ≤ 5000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsStars on One Straight Line HardDoes the Robot Cross Its Trail HardRope Around the Posts HardA Depot Close to All Shops HardBest View for a Turning Camera Hard
loading Python…
Input
plants=[[0, 0], [4, 0], [2, 1], [10, 10]], radius=2
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 128 tests on the server, hidden ones included.