Hard
Network Delay Time
Hard
11 submissions
50 coins
+200 XP
Graph
Problem Description
A network has `n` nodes labelled `1..n`. Each `[u, v, w]` in `times` is a directed link taking `w` time units. A signal is sent from node `k`. Return the time until every node has received it, or `-1` if some node never does.
**Example 1:**
```
Input: times = [[2, 1, 1], [2, 3, 1], [3, 4, 1]], n = 4, k = 2
Output: 2
```
**Example 2:**
```
Input: times = [[1, 2, 1]], n = 2, k = 1
Output: 1
```
**Example 3:**
```
Input: times = [[1, 2, 1]], n = 2, k = 2
Output: -1
```
Constraints
- `1 <= n <= 100`
- `1 <= times.length <= 6000`
- `1 <= w <= 100`
Need help?
Connect with expert programmers for real-time collaborative coding, video meetings, and whiteboard sessions via CodeConnect.
Video Call
Whiteboard
Live Coding
Screen Share