FreeCareerPath
Build the PrimitiveMedium

Cheapest Flights Within K Stops

Write `find_cheapest_price(n, flights, src, dst, k)` returning the cheapest price from `src` to `dst` using at most `k` stops, or `-1`. n=3, flights=[[0,1,100],[1,2,100],[0,2,500]], src=0, dst=2, k=0 -> 500 Dijkstra finalises a node at its cheapest cost, which may use too many stops — and a pricier route with fewer stops can be the only legal one. Bellman-Ford relaxes all edges `k + 1` times, so the hop bound is built into the iteration count. Relax from a *snapshot* of the previous round, or one round can chain several hops.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Cheapest Flights Within K Stops" are saved to your account — logging in takes a few seconds.

Cheapest Flights Within K Stops — FreeCareerPath