Find the cheapest flight from src to dst with at most K stops. Modified Dijkstra or BFS with level constraint. Bellman-Ford with K+1 iterations also works.
Bellman-Ford: relax all edges K+1 times. Each iteration allows one more stop. Use a copy of prices to avoid using updates from the same iteration.
💡 Pro tip: Understand this problem deeply — don't just memorize the code. Try explaining the approach out loud as if teaching a friend. If you can explain it simply, you truly understand it!
findCheapestPrice(3, flights, 0, 2, 1)
200
findCheapestPrice(3, flights, 0, 2, 0)
500