Detonate the Maximum Bombs - Problem

You are given a list of bombs. The range of a bomb is defined as the area where its effect can be felt. This area is in the shape of a circle with the center as the location of the bomb.

The bombs are represented by a 0-indexed 2D integer array bombs where bombs[i] = [xi, yi, ri]. xi and yi denote the X-coordinate and Y-coordinate of the location of the ith bomb, whereas ri denotes the radius of its range.

You may choose to detonate a single bomb. When a bomb is detonated, it will detonate all bombs that lie in its range. These bombs will further detonate the bombs that lie in their ranges.

Given the list of bombs, return the maximum number of bombs that can be detonated if you are allowed to detonate only one bomb.

Input & Output

Example 1 — Chain Reaction
$ Input: bombs = [[2,1,3],[6,1,4]]
Output: 2
💡 Note: Starting with bomb 0 at (2,1) with radius 3: it can reach bomb 1 at (6,1) since distance = 4 ≤ radius 3. Wait, that's wrong. Distance is 4 but radius is 3, so bomb 0 cannot reach bomb 1. Starting with bomb 1 at (6,1) with radius 4: it can reach bomb 0 at (2,1) since distance = 4 ≤ radius 4. So maximum is 2 bombs when starting with bomb 1.
Example 2 — No Chain Reaction
$ Input: bombs = [[1,1,5],[10,10,5]]
Output: 1
💡 Note: The two bombs are too far apart. Distance between (1,1) and (10,10) is √((10-1)² + (10-1)²) = √162 ≈ 12.7, which is greater than either bomb's radius of 5. No chain reaction possible, so maximum is 1.
Example 3 — Multiple Chain Reactions
$ Input: bombs = [[1,2,3],[2,3,1],[3,4,2],[4,5,3],[5,6,4]]
Output: 5
💡 Note: Starting from the right bomb and working backwards, we can create a chain reaction that detonates all 5 bombs due to their overlapping ranges.

Constraints

  • 1 ≤ bombs.length ≤ 100
  • bombs[i].length == 3
  • 1 ≤ xi, yi, ri ≤ 105

Visualization

Tap to expand
Detonate the Maximum Bombs: Chain Reaction ProblemABCBomb ARadius: 60Bomb BRadius: 50Bomb CRadius: 40ChainChainStart A: 3 bombsStart B: 2 bombsStart C: 1 bombMaximum: 3Goal: Find starting bomb that creates largest chain reaction
Understanding the Visualization
1
Input
Bombs with positions and explosion radius
2
Chain Reaction
Bombs detonate others within their range
3
Maximum Count
Find starting point that detonates most bombs
Key Takeaway
🎯 Key Insight: Model as directed graph where bombs can detonate others within their circular range
Asked in
Google 8 Amazon 5 Meta 3 Apple 2
32.2K Views
Medium Frequency
~25 min Avg. Time
847 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