← Practice · Graphs
Network Delay Time Medium
A network has n nodes labelled 1 to n. Each entry times[i] = [u, v, w] is a directed edge from u to v that takes w time. A signal is sent from node k. Return the time until all nodes have received it, or -1 if some node is unreachable.
Examples
times=[[2,1,1],[2,3,1],[3,4,1]], n=4, k=2 -> 2times=[[1,2,1]], n=2, k=2 -> -1
Define a function named networkDelayTime in JavaScript.
00:00
JavaScript · Tab indents · Ctrl/⌘+Enter runs the tests