Network Delay Time Mock Interview

  1. ✓Problem→
  2. 2Clarifying Questions→
  3. 3Constraints→
  4. 4Brute Force→
  5. 5Complexity Analysis→
  6. 6Pattern Recognition→
  7. 7Optimized Solution→
  8. 8Implementation→
  9. 9Testing→
  10. 10Follow-Up→
  11. 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?)