Network Delay Time
Explore how to determine the minimum time required for all nodes in a directed graph to receive a signal starting from a given node. Understand the use of graph algorithms to solve the network delay time problem efficiently, and practice implementing your solution.
We'll cover the following...
Statement
A network of n nodes labeled to is provided along with a list of travel times for directed edges represented as , where is the source node, is the target node, and is the delay time from the source node to the target node.
Considering we have a starting node, k, we have to determine the minimum time required for all the remaining nodes to receive the signal. Return if it’s not possible for all nodes to receive the signal.
Constraints:
-
kn -
times.length times[i].length-
n - Unique pairs of , which means that there should be no multiple edges
Examples
Understand the problem
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Network Delay Time
What is the minimum time it takes for all the n nodes to receive the signal?
times = [[3, 1, 1], [2, 3, 1], [2, 4, 1]]
n = 4
k = 2
1
2
3
-1
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself
Implement your solution in the following coding playground.
def network_delay_time(times, n, k):# Replace this placeholder return statement with your codereturn -1