← Questions

Detonate the most bombs in a chain reaction

0
GoogleCodingLast asked Apr 2026

A coding interview question asked in Google's onsite coding round, last asked Apr 2026. It tests graphs, bfs and dfs.

Each bomb has a position on a 2-D plane and a blast radius. When a bomb goes off, every bomb whose centre is within its radius goes off too, and those set off others in turn. Choose one bomb to detonate and return the largest number of bombs that can explode.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • max_detonated(bombs: list[list[int]]) -> int — each bomb is [x, y, r]. Bomb i sets off bomb j when the distance between their centres is <= r_i. Note this is one-directional: j may not reach back to i.

Example

max_detonated([[0,0,2], [2,0,2], [5,0,1]])             ->  2
# bombs 0 and 1 set each other off; neither reaches bomb 2

max_detonated([[0,0,4], [3,0,3], [6,0,3], [9,0,1]])    ->  4
# start at bomb 0 or 1 and the chain reaches all four

max_detonated([[1,1,5], [10,10,5]])                    ->  1

Constraints

  • 0 <= len(bombs) <= 100; -10^9 <= x, y <= 10^9; 0 <= r <= 10^9.
  • Use integer arithmetic for distances (squared values reach about 8 * 10^18).

Clarifying questions

  • Is the radius test inclusive?
  • Can two bombs share a position?
  • Can I choose more than one bomb to start?
  • How many bombs? (It decides whether O(n^3) is acceptable.)

What a strong answer covers

  • Build a directed graph: an edge i -> j when (xi - xj)^2 + (yi - yj)^2 <= ri^2, compared in integers with no square roots.
  • From each bomb, BFS or DFS and count reachable nodes; keep the maximum. O(n^2) to build plus O(n^3) worst case for the searches, fine for 100 bombs.
  • Why an undirected model (union-find) is wrong here.
  • Overflow in languages with fixed-size integers: squared distances reach about 8 * 10^18, which fits in a signed 64-bit integer but not in 32 bits, and a careless intermediate can still overflow.
  • Tests: no bombs, a single bomb, one-way reach, bombs at the same point, radius 0.

Follow-ups

  • Thousands of bombs: avoid O(n^2) edge building with a spatial grid, and reuse work through strongly connected components.
  • Return which bomb to start with.
  • You may start k bombs. Maximise the total.

Where it's asked

  • Google · Onsite coding · Last asked Apr 202645 min · Usually two rounds, mostly in person: whiteboard plus a Chromebook with Google Docs · No AI (a pilot code-comprehension round lets candidates use Gemini)

What it tests

graphs · bfs · dfs

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding