mediumAdvanced GraphsAmazonFacebook
Signal Broadcast Timer
A master clock sends a sync pulse from node k through a directed, weighted comm mesh. Return the moment every node has received the pulse.
Given n nodes labeled 1..n and times[i] = [u, v, w], return the minimum time for a signal from k to reach ALL nodes, or -1 if impossible.
Choose approach
1
2
u
3
4
1/5
Narrationstep 1 of 5
Settle node 2 at distance 0.
Variables
u=2
dist=0
How to think about it
- Minimum broadcast time = longest shortest-path from k.
- Priority queue extracts the current closest node.
- Infinity in any dist entry -> unreachable.
Edge cases to catch in interview
- Single node -> 0.
- Unreachable node -> -1.
Examples
Example 1
1{"n":2,"k":1,"times":[[1,2,1]]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed