Find the most bombs a single detonation can set off in a chain reaction

Quick Overview

Given bombs described by a center and a blast radius, find the largest number of bombs that one detonation can set off when every exploding bomb triggers all bombs inside its range. The problem tests turning a chain reaction into a graph, choosing the right edge direction, and searching for reachable nodes.

Find the most bombs a single detonation can set off in a chain reaction

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

You are given a list of bombs. The range of a bomb is the area where its effect can be felt. This area is a circle centered at the location of the bomb. The bombs are represented by a 0-indexed 2D integer array `bombs` where `bombs[i] = [x_i, y_i, r_i]`. `x_i` and `y_i` are the X and Y coordinates of the location of bomb `i`, and `r_i` is the radius of its range. You may choose to detonate a single bomb. When a bomb is detonated, it detonates all bombs that lie in its range. Those bombs in turn detonate the bombs that lie in their ranges, and so on. Given the list `bombs`, return the maximum number of bombs that can be detonated if you are allowed to detonate only one bomb. ### Function Signature ```python def maximum_detonation(bombs: list[list[int]]) -> int: ... ``` ### Rules - Bomb `j` lies in the range of bomb `i` when the Euclidean distance between their centers is at most `r_i`. A bomb exactly on the boundary of the circle counts as in range. - Range is one-directional: bomb `j` being in range of bomb `i` says nothing about whether bomb `i` is in range of bomb `j`. - The bomb you detonate first counts toward the total, and each bomb is counted once no matter how many explosions reach it. ### Constraints - `1 <= len(bombs) <= 100` - `len(bombs[i]) == 3` - `1 <= x_i, y_i, r_i <= 10^5` ### Examples ```text Input: bombs = [[2, 1, 3], [6, 1, 4]] Output: 2 ``` The bombs are 4 apart. Bomb 0 has radius 3, so it does not reach bomb 1, but bomb 1 has radius 4 and reaches bomb 0 because 4 <= 4. Detonating bomb 1 sets off both bombs. ```text Input: bombs = [[1, 1, 5], [10, 10, 5]] Output: 1 ``` The bombs are about 12.7 apart, which is more than either radius, so neither can trigger the other. Any single detonation sets off one bomb. ```text Input: bombs = [[1, 2, 3], [2, 3, 1], [3, 4, 2], [4, 5, 3], [5, 6, 4]] Output: 5 ``` Detonating bomb 0 sets off bombs 1 and 2 (squared distances 2 and 8, both at most 9). Bomb 2 then reaches bomb 3 (squared distance 2, at most 4), and bomb 3 reaches bomb 4 (squared distance 2, at most 9), so all five bombs go off.

Overview: Given bombs described by a center and a blast radius, find the largest number of bombs that one detonation can set off when every exploding bomb triggers all bombs inside its range. The problem tests turning a chain reaction into a graph, choosing the right edge direction, and searching for reachable nodes.

Nov 24, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

You are given a list of bombs. The range of a bomb is the area where its effect can be felt. This area is a circle centered at the location of the bomb.

The bombs are represented by a 0-indexed 2D integer array bombs where bombs[i] = [x_i, y_i, r_i]. x_i and y_i are the X and Y coordinates of the location of bomb i, and r_i is the radius of its range.

You may choose to detonate a single bomb. When a bomb is detonated, it detonates all bombs that lie in its range. Those bombs in turn detonate the bombs that lie in their ranges, and so on.

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

Function Signature

def maximum_detonation(bombs: list[list[int]]) -> int:
    ...

Rules

  • Bomb j lies in the range of bomb i when the Euclidean distance between their centers is at most r_i . A bomb exactly on the boundary of the circle counts as in range.
  • Range is one-directional: bomb j being in range of bomb i says nothing about whether bomb i is in range of bomb j .
  • The bomb you detonate first counts toward the total, and each bomb is counted once no matter how many explosions reach it.

Constraints

  • 1 <= len(bombs) <= 100
  • len(bombs[i]) == 3
  • 1 <= x_i, y_i, r_i <= 10^5

Examples

Input: bombs = [[2, 1, 3], [6, 1, 4]]
Output: 2

The bombs are 4 apart. Bomb 0 has radius 3, so it does not reach bomb 1, but bomb 1 has radius 4 and reaches bomb 0 because 4 <= 4. Detonating bomb 1 sets off both bombs.

Input: bombs = [[1, 1, 5], [10, 10, 5]]
Output: 1

The bombs are about 12.7 apart, which is more than either radius, so neither can trigger the other. Any single detonation sets off one bomb.

Input: bombs = [[1, 2, 3], [2, 3, 1], [3, 4, 2], [4, 5, 3], [5, 6, 4]]
Output: 5

Detonating bomb 0 sets off bombs 1 and 2 (squared distances 2 and 8, both at most 9). Bomb 2 then reaches bomb 3 (squared distance 2, at most 4), and bomb 3 reaches bomb 4 (squared distance 2, at most 9), so all five bombs go off.