Maximum Number of Darts Inside of a Circular Dartboard - Problem
Circular Dartboard Optimization Challenge
Alice has thrown
Now Bob wants to strategically place a circular dartboard of radius
Goal: Given the dart positions and the dartboard radius
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
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
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
ā Quadratic Growth
Space Complexity
O(1)
Only using variables to track maximum count and temporary calculations
ā 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
š”
Explanation
AI Ready
š” Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code