dsa8 min read
Bellman-Ford — Single-Source Shortest Path with Negative Edges [LC 787, Google, Amazon]
Master Bellman-Ford: relax every edge V-1 times to compute single-source shortest paths even with negative edges, and detect negative cycles in one extra pass. The algorithm behind LeetCode 787 Cheapest Flights Within K Stops, asked at Google, Amazon, and Meta.
Read →