JavaScript Solution - Dijkstra's algorithm
Runtime: 100 ms, faster than 92.92% of JavaScript online submissions for Network Delay Time.\nMemory Usage: 47.1 MB, less than 53.54% of JavaScript online submi
Runtime: 100 ms, faster than 92.92% of JavaScript online submissions for Network Delay Time.\nMemory Usage: 47.1 MB, less than 53.54% of JavaScript online submissions for Network Delay Time.\n\n```\nvar networkDelayTime = function(times, n, k) {\n    let graph = {};\n    let costs = {};\n    let parents = {};\n    let processed = {};\n    let processedCounter = 0;\n    \n    for (let time of times) {\n        if (!graph[time[0]]) {\n            graph[time[0]] = {};\n        } \n        graph[time[0]][time[1]] = time[2];\n        \n    }\n    \n    for (let i = 1; i <= n; i++) {\n        costs[i] = Infinity;\n        processed[i] = false;\n    }\n    costs[k] = 0;\n  \n    node = k;\n    \n    while (node !== -1) {\n        let cost = costs[node];\n        let neighbours = graph[node];\n        for (let neighbor in neighbours) {\n            let newCostOfNeighbor = cost + neighbours[neighbor];\n            if (newCostOfNeighbor < costs[neighbor]) {\n                costs[neighbor] = newCostOfNeighbor;\n                parents[neighbor] = node;\n            }\n        }\n        processed[node] = true;\n        processedCounter++;\n        node = findLowestCostNode(costs)\n    } \n    \n    function findLowestCostNode(costs) {\n        lowestCost = Infinity;\n        lowestCostNode = -1;\n        for (let node in costs) {\n            cost = costs[node];\n            if (cost < lowestCost && !processed[node]) {\n                lowestCost = cost;\n                lowestCostNode = node;\n            }\n        }\n        return lowestCostNode;\n    }\n    \n    if (processedCounter !== n) return -1;\n\n    let set = new Set();\n    for (let node in costs) {\n\t    set.add(costs[node]);\n    }\n    let max = Math.max(...set);\n    \n    return max;\n};\n```
['JavaScript']