743. Network Delay Time

Practice Network Delay Time for free on NudgeCode: Medium, Graph pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

A network has n nodes labeled 1 to n. Each times[i] = [u, v, w] is a directed link: a signal sent from u reaches v after w time units. A signal is sent from node k. Return how long it takes until every node has received it, or -1 if some node never does.

Example

times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2  ->  2

Constraints