Solution using Bellman-Ford shortest path algorithm
My solution using Bellman-Ford algorithm to find the shortest paths. The max of the shortest path is the time it takes to reach all the nodes.\n\n\nclass Soluti
My solution using Bellman-Ford algorithm to find the shortest paths. The max of the shortest path is the time it takes to reach all the nodes.\n\n```\nclass Solution {\n    // TC = O(T * N), SC = O(N), T-> length of times\n    // Using Bellman-Ford to find shortest paths from node K\n    public int networkDelayTime(int[][] times, int N, int K) {\n        int[] dist = new int[N];\n        for (int i = 0; i < dist.length; i++)\n            dist[i] = (int)1e9;\n        dist[K - 1] = 0;\n        for (int i = 0; i < N; i++) {\n            for (int[] time: times) {\n                if (dist[time[0] - 1] + time[2] < dist[time[1] - 1]) {\n                    dist[time[1] - 1] = dist[time[0] - 1] + time[2];                    \n                }\n            } \n        }\n        if (Arrays.stream(dist).anyMatch(i -> i == (int)1e9)) return -1;\n        return Arrays.stream(dist).max().orElse(-1);\n    }\n}\n```
[]