Graph Theory37 sections · 1633 units
Open in Course

LeetCode 787 Cheapest Flights Within K Stops - Problem Statement

(LeetCode 787)

You have nn cities connected by flights with costs. Find the cheapest route from city src to city dst with at most kk stops. A stop is an intermediate city between source and destination. This is a constrained shortest path problem. You cannot use standard Bellman-Ford because it finds paths with minimum edges, not constrained stops.

The constraint changes the relaxation logic. At most kk stops means at most k+1k+1 flights (edges). You need to control how many edges are used in the shortest path.