Find the shortest path in a weighted graph

by cascade_zenith184
Amazon
senior
coding
medium
pending
3
49

Started with a brief explanation of Dijkstra's algorithm, as it's commonly used for weighted graphs. I outlined how I would implement a priority queue to manage the nodes and their distances.

As I coded, the interviewer asked clarifying questions about handling negative weights and whether I considered using A* instead. I admitted that Dijkstra’s may not work well with negative weights and proposed modifications for that scenario.

The coding was smooth until I tripped over edge cases when I tested my solution, causing some confusion. The interviewer seemed engaged but pointed out potential optimizations I overlooked, prompting a quick discussion about alternative algorithms like Bellman-Ford.


Markdown supported