Maximum Number of Darts Inside of a Circular Dartboard - Problem

Alice is throwing n darts on a very large wall. You are given an array darts where darts[i] = [xi, yi] is the position of the i-th dart that Alice threw on the wall.

Bob knows the positions of the n darts on the wall. He wants to place a dartboard of radius r on the wall so that the maximum number of darts that Alice throws lie on the dartboard.

Given the integer r, return the maximum number of darts that can lie on the dartboard.

Note: A dart is considered to be on the dartboard if the distance from the center of the dartboard to the dart is at most r.

Input & Output

Example 1 — Basic Case
$ Input: darts = [[-2,0],[2,0],[0,2],[0,-2]], r = 2
Output: 4
💡 Note: Circle centered at (0,0) with radius 2 can cover all 4 darts positioned at distance 2 from origin
Example 2 — Partial Coverage
$ Input: darts = [[-3,0],[3,0],[2,6],[5,4],[0,9],[7,8]], r = 5
Output: 5
💡 Note: Optimal circle placement can cover at most 5 out of 6 darts given the radius constraint
Example 3 — Single Dart
$ Input: darts = [[1,2]], r = 1
Output: 1
💡 Note: With only one dart, any circle of radius 1 containing that dart covers exactly 1 dart

Constraints

  • 1 ≤ darts.length ≤ 100
  • darts[i].length == 2
  • -104 ≤ xi, yi ≤ 104
  • 1 ≤ r ≤ 5000

Visualization

Tap to expand
Maximum Darts in Circle ProblemInput: Dart Positions5 darts at various positionsCircle radius r = 50Process: Find Optimal CircleOptimal circle covers 4 dartsOutput: Maximum Count4Maximum darts coveredGoal: Place circle optimally to maximize dart coverage
Understanding the Visualization
1
Input
Given dart positions and circle radius r
2
Process
Find optimal circle placement to maximize coverage
3
Output
Return maximum number of darts that can be covered
Key Takeaway
🎯 Key Insight: The optimal circle passes through at least 2 darts on its boundary, reducing infinite possibilities to finite geometric calculations
Asked in
Google 15 Microsoft 12 Apple 8
12.5K Views
Medium Frequency
~35 min Avg. Time
234 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen