← Google Interview Insights

Google·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
May 2026

Summary

Google SWE coding round with a graph reachability problem. The bomb chain reaction question is a classic BFS/DFS setup dressed up in a fun scenario, and the squared distance trick is the thing that'll save you if you remember it.

Questions Asked (1)

Q1

Given n bombs each with a position and explosion radius, if detonating bomb i triggers any bomb j within its radius (and those can trigger further bombs), what is the maximum number of bombs you can detonate by choosing exactly one bomb to start?

Algorithms & Data Structures
Author's notes

Build a directed graph where there's an edge from i to j if j falls within i's blast radius, then run BFS or DFS from each node and track the max reachable count.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the bombs as a directed graph where an edge from i to j exists if bomb j lies within bomb i's blast radius. Then the problem reduces to finding the node with the largest reachable set, which can be computed using graph traversal (DFS/BFS) from each node or more efficiently with SCC condensation and DP. Finally, return the size of the largest reachable set.

Pro tip: Mention that building the graph naively is O(n^2), but for large n you can optimize edge construction using spatial indexing (e.g., k-d tree or grid) to avoid TLE. Also, clarify that the graph is directed: i can trigger j even if j cannot trigger i.

1. Clarify the problem and constraints

Confirm that detonation is directional (i triggers j if j is within i's radius) and that you can choose exactly one starting bomb. Ask about input size to determine if O(n^2) is acceptable.

2. Model as a directed graph

Create a directed graph with n nodes. For each bomb i, add edges to all bombs j (j ≠ i) such that the distance between i and j is ≤ radius_i. This captures the chain reaction.

3. Compute reachable set for each node

For each node, perform DFS/BFS to find all reachable nodes. The answer is the maximum size among these sets. If n is large, consider SCC condensation to avoid redundant traversals.

4. Optimize if needed

If n is large (e.g., >10^4), optimize graph construction using spatial data structures (e.g., k-d tree, grid) and use SCC + DP on the condensed DAG to compute reachable set sizes efficiently.

5. Analyze time and space complexity

State the complexity: O(n^2) for naive graph building and O(n*(n+m)) for BFS from each node, where m is number of edges. With SCC+DP, it's O(n+m) after building the graph.

Key Points to Mention

  • Directed graph representation: edges from i to j if j is within i's radius.
  • Reachability analysis: the answer is the size of the largest reachable set from any single node.
  • Graph traversal algorithms: BFS/DFS for each node, or SCC condensation for efficiency.
  • Spatial indexing for large n: k-d tree, grid, or sweep line to build edges faster than O(n^2).
  • Time and space complexity trade-offs: naive vs optimized approaches.
  • Edge cases: bombs with zero radius, overlapping radii, and disconnected components.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.