Budget trip with a stop limit
There are n cities numbered 0 to n - 1. Each entry of flights is [origin, target, price], a one-way flight. Return the lowest total price to travel from src to dst making at most k stops in between (that is, taking at most k + 1 flights), or -1 if no such route exists. If src == dst, the trip is free.
Prices are positive integers; the same flight may appear twice.
Besides the tests, one large input (100 cities, 1,000 flights) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
cheapest_fare(3, [[0,1,40],[1,2,30],[0,2,90]], 0, 2, 1)→70cheapest_fare(3, [[0,1,40],[1,2,30],[0,2,90]], 0, 2, 0)→90cheapest_fare(4, [[0,1,1],[1,2,1],[2,3,1]], 0, 3, 1)→-1