The Network Delay Time problem gives you a directed weighted graph representing network nodes and signal travel times. A signal is sent from a source node. Find the minimum time for the signal to reach all nodes, or return -1 if any node is unreachable. This Network Delay Time coding problem is the canonical application of Dijkstra's algorithm for single-source shortest paths.
Microsoft, Meta, Amazon, Netflix, Google, and Bloomberg ask this as the standard Dijkstra's algorithm problem. It validates that candidates can implement single-source shortest paths cleanly on a directed graph with a min-heap. The shortest path, BFS, graph, DFS, and heap interview pattern is comprehensively demonstrated here.
Dijkstra's algorithm. Build an adjacency list from the edge list. Initialize dist[source] = 0, all others = infinity. Use a min-heap: (distance, node). Process the node with minimum distance, relaxing all outgoing edges. When a shorter path is found, push the updated distance to the heap. After processing all reachable nodes, the answer is max(dist) if all nodes are reached, or -1 otherwise.
Nodes: 4, edges: [(2,1,1),(2,3,1),(3,4,1),(1,4,2)], source=2.
Network Delay Time is the textbook Dijkstra problem. Implement it until you can write it fluently from memory: adjacency list construction, min-heap initialization, relaxation loop, max-dist computation. Common follow-ups: "what if edges can be negative?" (Bellman-Ford), "what if you need all-pairs shortest paths?" (Floyd-Warshall). Being able to discuss these alternatives shows comprehensive graph knowledge.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find Edges in Shortest Paths | Hard | Solve | |
| Cheapest Flights Within K Stops | Medium | Solve | |
| The Maze II | Medium | Solve | |
| Minimize the Maximum Edge Weight of Graph | Medium | Solve | |
| Minimum Path Cost in a Hidden Grid | Medium | Solve |