Dijkstra's Shortest Path Problem
Dijkstra's Shortest Path Problem — ExecCode Medium DSA Practice
Solve the Dijkstra's Shortest Path problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given a directed weighted graph with non-negative edge weights, compute shortest-path distances from source src to every node using Dijkstra with a min-heap. Return the dist array.
Examples
Input n = 7, edges = [[0, 1, 4], [0, 2, 1], [2, 1, 2], [1, 3, 1], [2, 3, 5], [3, 4, 3], [2, 5, 7], [5, 4, 1], [4, 6, 2], [3, 6, 9]], src = 0; Output [0, 3, 1, 4, 7, 8, 9]. Input n = 2, edges = [[0, 1, 5]], src = 0; Output [0, 5]
Constraints
1 ≤ n ≤ 10^5 0 ≤ edges.length ≤ 2*10^5 Weights ≥ 0 0 ≤ src < n
Practice Dijkstra's Shortest Path free on ExecCode. Browse DSA problems, topic map, and placement guides.