Problem · Array

Detonate Bombs with Chain Reactions

Learn this problem
MediumAirbnb logoAirbnbFULLTIMEPHONE SCREEN

Problem statement

Each entry bombs[i] = [x, y, radius] describes a bomb centered at (x, y). When bomb i detonates, it immediately detonates every still-undetonated bomb whose center is at Euclidean distance at most radius from (x, y). Those bombs can trigger further detonations.

You may choose exactly one bomb to detonate first. Return the maximum number of bombs that can detonate in the resulting chain reaction.

Function

maximumDetonation(bombs: int[][]) → int

Examples

Example 1

bombs = [[2,1,3],[6,1,4]]return = 2

The second bomb reaches the first because their centers are 4 units apart and its radius is 4. Starting from the second bomb detonates both.

Example 2

bombs = [[1,1,5],[10,10,5]]return = 1

Neither bomb's radius reaches the other, so any chain contains only its starting bomb.

Example 3

bombs = [[1,1,3],[4,1,3],[7,1,3],[10,1,1]]return = 4

Starting from the first bomb triggers the next bomb at distance 3, and the reaction continues through all four bombs.

Constraints

  • 1 <= bombs.length <= 100.
  • Every entry in bombs has exactly three integers.
  • 1 <= x, y, radius <= 100000.

More Airbnb problems

drafts saved locally
public int maximumDetonation(int[][] bombs) {
    // Write your code here.
}
bombs[[2,1,3],[6,1,4]]
expected2
checking account