Answer Latency-Limited Reachability Queries Offline in a Backbone
Last updated: November 29, 2026
Quick Overview
A backbone has n routers and undirected links with latencies (parallel links allowed). Each query (p, q, limit) asks whether p can reach q using only links whose latency is strictly below limit. Answer all queries.
0
0
0 solved
A backbone has n routers and undirected links with latencies (parallel links allowed). Each query (p, q, limit) asks whether p can reach q using only links whose latency is strictly below limit. Answer all queries.
Google network planning asks questions like 'which sites stay connected if we only allow low-latency paths', and this onsite question tests offline query processing. The interviewer checks that you sort both links and queries by threshold, sweep once with union-find, and restore answers to the original query order.
What the Interviewer Expects
- Explains why a BFS per query is too slow
- Sorts links by latency and queries by limit
- Sweeps once, adding links below each query's limit
- Uses the strict inequality correctly
- Writes answers back by original query index
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Queries arrive online and cannot be sorted. What structure would you use?
- Return the minimum limit needed for each pair instead of a boolean.
- How would you support link removals between queries?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
n, list of(a, b, latency), and list of(p, q, limit). - A path may use only links with latency
< limit. - Output: list of booleans in the original query order....
High-Level Design
A query with a larger limit allows a superset of the links of a smaller-limit query, so if we process queries by increasing limit, the usable link set only grows. That makes it a pure union-find probl...