Deviopath › JavaScript

Shortest Distances (Dijkstra)

Hard · Graphs

A directed graph has nodes numbered 0 to n - 1. Each edge is [from, to, weight] with a non-negative weight.

Write a function shortestDistances that returns an array where index i holds the length of the shortest path from start to node i. Use -1 for nodes that cannot be reached. The distance from start to itself is 0.

Next: Minimum Coins