Answer Latency-Bounded Reachability Queries Between Data Centers
Last updated: November 29, 2026
Quick Overview
Given n data centers, network links (u, v, latency), and queries (u, v, limit), answer for each query whether u can reach v using only links with latency strictly below limit.
ByteDance
November 29, 20260
0
0 solved
Given n data centers, network links (u, v, latency), and queries (u, v, limit), answer for each query whether u can reach v using only links with latency strictly below limit.
ByteDance runs traffic across many regions, and routing teams ask whether two sites stay connected if slow links are excluded. This offline union-find problem in the style of ByteDance onsites checks whether you sort both queries and edges to avoid running a BFS per query.
What the Interviewer Expects
- Note that per-query BFS is O(q * (V + E)) and too slow
- Sort links by latency and queries by limit
- Add links incrementally with union-find as the limit grows
- Restore answers to the original query order
- State O((E + q) log(E + q)) time
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 must be answered online in arrival order: what structure helps?
- Instead of a boolean, return the minimum possible bottleneck latency between u and v.
- Links can fail and be removed: how does that change the approach?
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 nodes, a list of (u, v, latency) links (parallel links allowed), and queries (u, v, limit). Output: a list of booleans aligned with the queries. Strictly below limit, so a link with latency e...
High-Level Design
Process queries offline in increasing order of limit. Keep a pointer into links sorted by latency and union every link whose latency is below the current limit. Because limits only grow, the set of al...