Detonate the Maximum Bombs

MediumGraphsdfs

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You are given bombs, where bombs[i] = [x, y, r] places a bomb at (x, y) with blast radius r. When a bomb explodes, every bomb whose center lies within or exactly on its circle (Euclidean distance <= r) also explodes, which can set off further bombs in turn. Note that the relationship is **one-directional**: bomb A reaching B does not mean B reaches A. You may manually detonate exactly one bomb. Return the maximum number of bombs that end up exploding (including the one you detonate). Compare squared distances with integers to avoid precision issues.

Examples

Input: bombs = [[1,1,4],[5,1,2],[7,1,3],[20,20,1]]
Output: 3
Bomb 0 reaches bomb 1 (distance 4), and bomb 1 reaches bomb 2 (distance 2), so detonating bomb 0 sets off three bombs.
Input: bombs = [[0,0,1],[5,5,1]]
Output: 1
The bombs are too far apart to trigger each other.

Constraints

  • 1 <= bombs.length <= 100
  • 1 <= x, y, r <= 10^5
  • Squared distances can exceed 32-bit range; use 64-bit arithmetic

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More dfs problems