Skip to interview prep
Apexed

63. Network Delay Time (Dijkstra)

MediumGraphs

Directed edges times[i] = [u, v, w] take w milliseconds. Nodes are labelled 1 to n. A signal starts at node k. Return the time for all nodes to receive 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

Constraints

  • 1 ≤ n ≤ 100
  • Weights are non-negative

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Network Delay Time (Dijkstra) — coding interview practice — Apexed