Recognized Dijkstra pretty fast, which was good.
Clarify that the graph is weighted and directed, and that edge weights are non-negative (or handle negative weights if allowed). Use Dijkstra's algorithm with a priority queue to compute shortest distances from the source to all nodes, then extract distances for the target nodes. If negative weights are possible, use Bellman-Ford instead.
Pro tip: Mention that you can stop Dijkstra early once all target nodes are settled, which can save time if the target set is small. Also, discuss how to handle large graphs by using an adjacency list and a min-heap for efficiency.
Ask about edge weight ranges (non-negative?), graph size, and whether the graph is static. Confirm the expected output format (array of distances in the order of targets).
If weights are non-negative, Dijkstra's algorithm is optimal. If negative weights exist, Bellman-Ford is needed. Mention time complexities: O((V+E) log V) for Dijkstra with a binary heap.
Use an adjacency list to represent the graph and a priority queue (min-heap) to repeatedly extract the node with the smallest tentative distance. Maintain a distance array initialized to infinity, with the source set to 0.
After running the algorithm, iterate through the target list and return the distance if it's less than infinity, otherwise -1. Optionally, stop early if all targets are settled.
Discuss time and space complexity, and consider edge cases: unreachable targets, source equals target, multiple edges, and large graphs. Mention potential optimizations like early termination.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.