A CDN pushes a config update from an origin server to n edge servers numbered 0 to n - 1. Each links[i] = [from, to, ms] means server from can forward the update to server to, and it takes ms milliseconds to arrive. Every server forwards the update as soon as it receives it.
Write lastUpdateTime(n, links, origin) that returns how many milliseconds pass until every server has the update, or -1 if some server never gets it.
Input: n = 4, links = [[0,1,1],[0,2,4],[1,2,2],[2,3,1]], origin = 0 Output: 4
Server 2 is fastest through 1 (1 + 2 = 3 ms), so server 3 gets it at 4 ms, the last one.
Input: n = 2, links = [[0,1,5]], origin = 1 Output: -1
The only link goes from server 0 to server 1, so the update can't travel from server 1 back to server 0.
1 <= n <= 10000 <= links.length <= 100000 <= ms <= 1000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #459 When Does the Last Edge Server Update?. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.