medium
Cheapest Flights Within K Stops
Given n cities, directed flights with prices, a source, a destination and an integer k, return the cheapest price from source to destination using at most k intermediate stops. Return -1 if no such route exists.
Constraints
- 1 ≤ n ≤ 100
- 0 ≤ flights.length ≤ (n · (n - 1) / 2)
- 1 ≤ price ≤ 10^4
- 0 ≤ k < n
Examples
in: n = 4, flights = [[0,1,100],[1,2,100],[2,0,100],[1,3,600],[2,3,200]], src = 0, dst = 3, k = 1
out: 700
Code it yourself
Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?
Choose an approach to check your pattern recognition, or reveal the discussion when you need help.