← All mock interviewsHints used: 0
Network Delay Time Mock Interview
- ✓Problem→
- 2Clarifying Questions→
- 3Constraints→
- 4Brute Force→
- 5Complexity Analysis→
- 6Pattern Recognition→
- 7Optimized Solution→
- 8Implementation→
- 9Testing→
- 10Follow-Up→
- 11Evaluation
Problem
You are given a network of n nodes labelled 1 … n and a list of directed edges times[i] = [u, v, w] meaning a signal sent from u reaches v after w units of time. A signal is sent from node k. Return the minimum time for all nodes to receive the signal, or -1 if it is impossible for every node to receive it.
Constraints
- 1 ≤ k ≤ n ≤ 100
- 1 ≤ times.length ≤ 6000
- 0 ≤ w ≤ 100
- no self-edges or duplicate edges
Example
in: n = 4, k = 2, times = [[2,1,1],[2,3,1],[3,4,1]]
out: 2
Clarify
Before choosing anything: what would you ask the interviewer? What assumptions are you making? (Duplicates? Empty input? Value ranges? What to return when there is no answer?)