Code Room
CodingMediumcod-g785
Subject Priority queuesLevel Mid–Senior~30 minCommon in Algorithms & data structures interviewsIndustries Software development, Technology

Question

Given n nodes labeled 0..n-1 and a list of directed weighted edges [u, v, w] with w >= 0, find the shortest-path distance from node `src` to every node. Return a list of length n where index i is the distance to node i, or -1 if unreachable. Use a priority queue. The graph may have multiple edges between the same pair.

Implement
dijkstra(n: int, edges: list[list[int]], src: int) → list[int]
Examples
in[5,[[0,1,4],[0,2,1],[2,1,2],[1,3,1],[2,3,5]],0]out[0,3,1,4,-1]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.