Maximum Number of Darts Inside of a Circular Dartboard - Problem
Circular Dartboard Optimization Challenge

Alice has thrown n darts at a massive wall, and you know the exact coordinates where each dart landed: darts[i] = [xi, yi] represents the position of the i-th dart.

Now Bob wants to strategically place a circular dartboard of radius r on the wall to maximize the number of Alice's darts that fall within or on the boundary of his dartboard.

Goal: Given the dart positions and the dartboard radius r, find the maximum number of darts that can be enclosed by optimally positioning the circular dartboard.

Note: A dart is considered inside the dartboard if the distance from the dart to the center of the dartboard is less than or equal to r.

Input & Output

example_1.py — Basic Square Pattern
$ Input: darts = [[-2,0],[2,0],[0,2],[0,-2]], r = 2
› Output: 4
šŸ’” Note: A circle of radius 2 centered at origin (0,0) can cover all 4 darts positioned at the cardinal directions. Each dart is exactly distance 2 from the center, so they lie on the boundary of the circle.
example_2.py — Scattered Points
$ Input: darts = [[-3,0],[3,0],[2,6],[5,4],[0,9],[7,8]], r = 5
› Output: 5
šŸ’” Note: The optimal dartboard placement can cover at most 5 darts. By carefully positioning the circle, we can include most points while staying within the radius constraint.
example_3.py — Single Point Edge Case
$ Input: darts = [[0,0]], r = 1
› Output: 1
šŸ’” Note: With only one dart, the maximum possible coverage is 1. The dartboard can be placed anywhere that includes this single dart.

Visualization

Tap to expand
šŸŽÆ Dartboard Coverage OptimizationSuboptimal: 5 darts coveredOptimal: 6 darts covered2 darts on boundary
Understanding the Visualization
1
Brute Force Attempt
Try placing spotlight center at each target location - simple but misses optimal positions
2
Key Insight
Optimal spotlight position will always have at least 2 targets on its edge - this constrains possible positions
3
Geometric Solution
For each pair of targets, calculate all possible spotlight centers that put both targets on the edge
4
Count and Compare
For each valid spotlight position, count illuminated targets and track the maximum
Key Takeaway
šŸŽÆ Key Insight: The optimal dartboard position always has at least 2 darts on its circumference, dramatically reducing the search space from infinite positions to O(n²) candidates.

Time & Space Complexity

Time Complexity
ā±ļø
O(n²)

For each of n darts, we check distance to all other n darts

n
2n
⚠ Quadratic Growth
Space Complexity
O(1)

Only using variables to track maximum count and temporary calculations

n
2n
āœ“ Linear Space

Constraints

  • 1 ≤ darts.length ≤ 100
  • darts[i].length == 2
  • -104 ≤ xi, yi ≤ 104
  • 1 ≤ r ≤ 5000
  • All dart coordinates are distinct
  • Answers within 10-5 of the expected value are accepted
Asked in
Google 23 Amazon 18 Meta 15 Apple 12
28.2K Views
Medium Frequency
~35 min Avg. Time
856 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