Trains the technique from
LeetCode 743Network Delay TimeThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A courier firm runs depots sorting depots numbered 1 through depots. Its one-way
shuttle legs are listed in legs, where legs[i] = [u_i, v_i, w_i] means a shuttle leaves
depot u_i for depot v_i and the crossing takes w_i minutes. A leg is usable in that
direction only. No two legs share the same ordered pair of depots.
At minute 0 a dispatch note is posted at depot origin. A depot forwards a copy of the note
along every leg leaving it the instant the note arrives, and copies travel at the same time
without interfering. A depot counts as served the first moment any copy reaches it, and the
origin is served at minute 0. Some legs take 0 minutes.
Return the minute at which the last depot is served. If at least one depot is never served,
return -1.
Example 1
Depot 1 holds the note at minute 0, depot 2 is served at minute 3, and a copy forwarded from depot 2 serves depot 3 at minute 7. The last depot is therefore served at minute 7.
Example 2
The only leg runs from depot 2 to depot 1, and legs are one-way, so nothing ever leaves depot 1 and depot 2 stays unserved.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def broadcast_time(legs: list[list[int]], depots: int, origin: int) -> int:public int broadcastTime(int[][] legs, int depots, int origin)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.