Back to problems

Cheapest Flights Within K Stops

Algorithm · Uber · Hard

There are n cities joined by a collection of flights. The array flights uses entries of the form flights[i] = [from_i, to_i, price_i], representing a flight that travels from city from_i to city to_i and costs price_i. For the given src, dst, and k, determine the minimum price of a route from src to dst that uses no more than k stops. Return -1 when no route satisfies that limit. Examples Example 1: Input: n = 4, flights = [[0,1,100],[1,2,100],[2,0,100],[1,3,600],[2,3,200]],…

Checking your access…