The Find Edges in Shortest Paths interview question is a high-level graph problem. You are given a weighted, undirected graph with n nodes and a list of edges. Your goal is to find all the edges that belong to at least one shortest path between a starting node (usually node 0) and a target node (usually node n-1). You need to return a boolean array where each entry indicates if the corresponding edge is part of a shortest path.
This Find Edges in Shortest Paths coding problem is used by firms like DoorDash to assess a candidate's mastery of graph theory and pathfinding optimizations. It requires more than just finding one shortest path; it requires understanding the mathematical relationship between distances. It tests your ability to apply Dijkstra's algorithm effectively and reason about edge weights in a complex network.
This problem follows the Shortest Path, Graph, Heap (Priority Queue) interview pattern. The core insight is that an edge (u, v) with weight w is part of a shortest path from S to T if: Dist(S, u) + w + Dist(v, T) == TotalShortestDist or Dist(S, v) + w + Dist(u, T) == TotalShortestDist. To solve this, you run Dijkstra twice: once starting from S and once starting from T.
Suppose we have nodes 0, 1, 2 and edges:
For path problems involving "all shortest paths," always consider running your algorithm from both directions (source-to-all and destination-to-all). This "meet-in-the-middle" logic often simplifies path validation from O(E) complexity down to a simple O(1) check per edge.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Network Delay Time | Medium | Solve | |
| Cheapest Flights Within K Stops | Medium | Solve | |
| The Maze II | Medium | Solve | |
| The Maze III | Hard | Solve | |
| Minimize the Maximum Edge Weight of Graph | Medium | Solve |