Gamified challenge · Dijkstra
There are n towers numbered 0 to n - 1. Each entry [u, v, t] of times is a one-way cable: a signal at tower u reaches tower v after t time units (t ≥ 1). Tower src broadcasts at time 0, and every tower relays the signal down all its cables the moment it first hears it.
Write delay(times, n, src) that returns the time at which the last tower hears the signal, or -1 if some tower never hears it.
Example: with times = [[0,1,4],[0,2,1],[2,1,2],[1,3,1],[2,3,5],[3,4,3]], n = 5, src = 0, towers hear it at 0, 3, 1, 4, 7, so the answer is 7.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google