MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / networkDelayTime

Method networkDelayTime

NetworkDelayTime.java:30–47  ·  view source on GitHub ↗
(int[][] times, int n, int k)

Source from the content-addressed store, hash-verified

28 }
29 //time complexity!
30 public int networkDelayTime(int[][] times, int n, int k) {
31 ArrayList<ArrayList<int[]>> adj = new ArrayList<>();
32 for(int i=0;i<n;i++){
33 adj.add(new ArrayList<>());
34 }
35 for(int time[] : times){
36 int u = time[0]-1;
37 int v = time[1]-1;
38 int w = time[2];
39 adj.get(u).add(new int[]{v,w});
40 }
41 int minTime[] = dijkstra(k-1,n, adj);
42 int res = Integer.MIN_VALUE;
43 for(int time : minTime){
44 res = Math.max(res,time);
45 }
46 return (res==Integer.MAX_VALUE)?-1:res;
47 }
48}

Callers

nothing calls this directly

Calls 2

dijkstraMethod · 0.95
addMethod · 0.45

Tested by

no test coverage detected