...

/

Network Delay Time

Network Delay Time

Try to solve the Network Delay Time problem.

Statement

A network of n nodes labeled 11 to nn is provided along with a list of travel times for directed edges represented as times[i]=(xi, yi, ti)times[i]=(x_i​, \space y_i, \space t_i​), where xix_i​ is the source node, yiy_i​ is the target node, and tit_i​ 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 n1n - 1 nodes to receive the signal. Return 1-1 if it’s not possible for all n1n - 1 nodes to receive the signal.

Constraints:

  • 11 \leq k \leq n \leq 100100
  • 11 \leq times.length \leq 60006000
  • times[i].length ==3== 3
  • 1x,y1 \leq x, y \leq n
  • xx !=!= yy
  • 0t1000 \leq t \leq 100
  • Unique pairs of (x,y)(x, y), which means that there should be no multiple edges

Examples

1 / 3

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

1

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

A)

1

B)

2

C)

3

D)

-1

Question 1 of 30 attempted

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.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4
5

Try it yourself

Implement your solution in the following coding playground.

Press + to interact
Java
usercode > NetworkDelay.java
import java.util.*;
class NetworkDelay {
public static int networkDelayTime(int[][] times, int n, int k) {
// Replace this placeholder return statement with your code
return -1;
}
}
Network Delay Time

Access this course and 1200+ top-rated courses and projects.