Detonate the Maximum Bombs - Problem
The Chain Reaction Challenge!

Imagine you're a demolitions expert working on a controlled explosion site. You have multiple bombs placed at different locations, each with its own blast radius. Here's the exciting part: when you detonate one bomb, it can trigger a chain reaction!

How it works:
• Each bomb is located at coordinates (x, y) with a circular blast radius r
• When a bomb explodes, it detonates ALL bombs within its blast radius
• Those newly detonated bombs will also explode, potentially triggering even more bombs
• This creates a cascading chain reaction!

Your Mission: Choose the optimal starting bomb to maximize the total number of bombs that explode in the chain reaction. You can only manually detonate one bomb initially - the rest must be triggered by the chain reaction.

Input: A 2D array where bombs[i] = [xi, yi, ri] represents the x-coordinate, y-coordinate, and blast radius of the i-th bomb.

Output: The maximum number of bombs that can be detonated by choosing the optimal starting bomb.

Input & Output

example_1.py — Basic Chain Reaction
$ Input: bombs = [[2,1,3],[6,1,4]]
Output: 2
💡 Note: The optimal choice is to detonate bomb 0. Bomb 0 detonates bombs 1, which forms a chain reaction that detonates bomb 1. So 2 bombs are detonated.
example_2.py — Complex Chain
$ Input: bombs = [[1,1,5],[10,10,5]]
Output: 1
💡 Note: Detonating either bomb will only destroy 1 bomb (itself) because they are too far apart to trigger each other.
example_3.py — Maximum Chain Reaction
$ Input: bombs = [[1,2,3],[2,3,1],[3,4,2],[4,5,3],[5,6,4]]
Output: 5
💡 Note: Starting from bomb 0 creates a chain reaction that eventually detonates all bombs: 0→1, 0→2→3→4. Total: 5 bombs.

Constraints

  • 1 ≤ bombs.length ≤ 100
  • bombs[i].length == 3
  • 1 ≤ xi, yi, ri ≤ 105
  • Important: Use long long to avoid integer overflow when calculating distances

Visualization

Tap to expand
💥 Chain Reaction Explosion Simulator 💥💣 START💣 #2💣 #3💣 #4💣 #5Chain Count5 💣Max Found!🔍 Step 1: Build detonation graph (O(n²))🚀 Step 2: DFS from each bomb (O(n²))Result: Maximum chain reaction = 5 bombs💡 Key: Transform geometry → graph connectivity
Understanding the Visualization
1
Map Blast Zones
Each bomb has a circular blast radius - identify which bombs are within range of others
2
Build Connection Graph
Create directed edges from each bomb to all bombs it can detonate
3
Test Each Starting Point
For each bomb, simulate the complete chain reaction using graph traversal
4
Find Maximum Impact
Return the starting bomb that produces the largest chain reaction
Key Takeaway
🎯 Key Insight: Convert the geometric bomb detonation problem into a graph connectivity problem. Pre-compute which bombs can trigger others, then use DFS/BFS to find the maximum reachable bombs from any starting point.
Asked in
Google 15 Amazon 12 Meta 8 Microsoft 6
28.4K Views
Medium Frequency
~25 min Avg. Time
892 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