Deviopath › TypeScript

Shortest Distances (Dijkstra)

Hard · Graphs

A directed graph is given as a list of nodes and a list of weighted edges (weights are never negative).

Write shortestDistances(nodes, edges, start) that returns an object with one key for every node in nodes. The value is the length of the shortest path from start to that node, or -1 if the node cannot be reached. The distance from start to itself is 0.

Use Dijkstra's algorithm.

Next: Pack the Backpack (0/1 Knapsack)