← Google Interview Insights

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

IntermediatePrefer not to say
Jun 2026

Summary

Google SWE coding round with a graph reachability problem that looks deceptively simple but has some tricky edge cases around the distance threshold being strict versus inclusive. The black-box function constraint made it feel more real-world than your typical LeetCode graph question.

Questions Asked (1)

Q1

Given a set of 2D points, a start, a target, a distance threshold r, and a black-box getDistance function, determine whether there is a path from start to target where each hop between points has a distance strictly less than r.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was BFS and that part was fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the points as nodes in a graph where edges exist between points with distance < r, then perform BFS/DFS from start to target. Discuss the trade-offs of implicit graph traversal versus explicit edge construction, and consider optimizations like spatial partitioning for large datasets.

Pro tip: Clarify whether the distance function is symmetric and whether the points are static; if not, the graph may be directed or dynamic, affecting the algorithm choice. Also, mention that early termination upon reaching the target can save time.

1. Clarify problem constraints

Ask about the number of points, whether getDistance is symmetric, and if the points are static. This determines if the graph is undirected and if pre-processing is possible.

2. Choose graph representation

Decide between building an explicit adjacency list (O(n^2) edges) or using an implicit graph where neighbors are found on-the-fly by checking all points. The latter avoids O(n^2) memory but may be slower.

3. Select traversal algorithm

Use BFS for shortest path in terms of hops or DFS for any path. Both are O(V+E) for explicit graphs; for implicit graphs, each node expansion takes O(n) distance checks.

4. Optimize with spatial indexing

For large n, use a spatial data structure like a k-d tree or grid to quickly find neighbors within distance r, reducing the number of getDistance calls.

5. Analyze complexity and trade-offs

Compare time and space complexity of approaches. Explicit graph: O(n^2) time and space. Implicit with spatial index: O(n log n) average time, O(n) space. Discuss when each is appropriate.

Key Points to Mention

  • Graph modeling: points as nodes, edges if distance < r
  • BFS/DFS traversal for connectivity
  • Time and space complexity: O(n^2) for explicit graph, O(n^2) time for implicit without index
  • Spatial indexing (k-d tree, grid) to optimize neighbor queries
  • Handling edge cases: start equals target, no path, disconnected components
  • Trade-offs between pre-processing and on-the-fly computation

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