Flag Every Network Link That Lies on Some Shortest Route
Last updated: November 29, 2026
Quick Overview
Given an undirected weighted graph, return a boolean for each edge saying whether it belongs to at least one shortest path from node 0 to node n-1.
Meta
November 29, 20260
0
0 solved
Given an undirected weighted graph, return a boolean for each edge saying whether it belongs to at least one shortest path from node 0 to node n-1.
Relevant to Meta network engineering, where knowing which backbone links carry shortest-path traffic tells you which links are critical. The interviewer checks whether you combine distances from both endpoints instead of enumerating paths. It is a common onsite follow-on after a basic Dijkstra.
What the Interviewer Expects
- Run Dijkstra from the source and from the target
- State the test ds[u] + w + dt[v] == best in either direction
- Avoid enumerating shortest paths, which can be exponential
- Handle an unreachable target
- Discuss integer weights versus float equality
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 find edges on every shortest path, not just some?
- How would you count shortest paths through each edge?
- What changes for a directed graph?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
nup to 5 * 10^4, edges up to 5 * 10^4 with positive integer weights.- Output a list of booleans aligned with the input edge order....
High-Level Design
An edge (u, v, w) lies on a shortest path exactly when going from source to u, across the edge, then from v to the target costs the optimum. Because the graph is undirected, check both orientati...