Answer Reachability Queries Under a Per-Link Latency Limit
Last updated: November 29, 2026
Quick Overview
A network has n servers and undirected links [u, v, latency]; multiple links between the same pair are allowed. For each query [p, q, limit], return whether p can reach q using only links with latency strictly less than limit.
Meta
November 29, 20260
0
0 solved
A network has n servers and undirected links [u, v, latency]; multiple links between the same pair are allowed. For each query [p, q, limit], return whether p can reach q using only links with latency strictly less than limit.
A hard Meta onsite question rooted in traffic engineering across data center networks, where a route is acceptable only if every hop is under a latency budget. The interviewer looks for the offline trick: sort queries and links by threshold and sweep, adding links to a union find so every query is answered in near-constant time.
What the Interviewer Expects
- Reject a BFS per query as O(q (n + e))
- Sort links by latency and queries by limit
- Sweep, unioning links below the current limit
- Remember original query indices to restore output order
- Respect the strict less-than condition
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
- How would you answer queries online, in the order they arrive?
- What structure answers 'smallest limit that connects p and q' directly?
- How would you handle link latencies that change over time?
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,links[u, v, w],queries[p, q, limit]. - Output: list of booleans in query order.
- A path is valid when every link on it has
w < limit....
High-Level Design
For a fixed limit, the usable links form a subgraph, and the query is a connectivity check. As the limit grows the subgraph only gains links, which is exactly what union find supports.
So answer quer...