Network Delay Time
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given a directed, weighted network of n nodes labeled from 1 to n. A signal is broadcast from a single source node and propagates along the network's directed edges.
The connections are described by a list times, where each entry times[i] = [u, v, w] means a signal sent from node u reaches node v after exactly w units of time travelling along that directed edge. A signal may fan out: when it arrives at a node, it is simultaneously forwarded along every outgoing edge of that node.
Given times, the number of nodes n, and the label k of the source node, return the minimum amount of time required for the signal to reach **every** node in the network. If it is impossible for all n nodes to receive the signal, return -1.
The time for a single node to be reached is the length of the shortest path from k to that node. The answer is the largest of these shortest-path times over all nodes, since the whole network is "covered" only once the slowest-reached node has gotten the signal.
Examples
Constraints
- `1 <= k <= n <= 100`
- `0 <= times.length <= n * (n - 1)`
- `times[i].length == 3`
- `1 <= u, v <= n`
- `u != v` (no self-loops)
- `1 <= w <= 100`
- All `(u, v)` pairs are unique (no duplicate directed edges)
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.