Network Delay Time
Write the code, see it run, pass the checks.
The problem
- medium
- Code
- Pro
Write networkDelay(n, edges, start). A network has n nodes numbered 0 to n − 1, and each triple [from, to, time] in edges is a one-way link that carries a signal from one node to another in that many milliseconds, a positive whole number. A signal leaves start at time 0 and travels along every link. Return how long it takes until every node has received it, or -1 if some node never does. For example, networkDelay(4, [[1, 0, 1], [1, 2, 1], [2, 3, 1]], 1) is 2. The checks include 3,000 nodes and 100,000 links, so relaxing every link once per node is too slow.
Your code must pass
- Finds when the last node gets the signal
- Takes a faster route through other nodes
- Returns -1 when a node never gets the signal
- Handles a single node
- Is fast enough for 3,000 nodes and 100,000 links