Google | Onsite Question | US | L3/L4
Anonymous User
1650

Given a list of edges, a list of stations, and a tank_size. Determine the minimum number of steps it takes to get from start to destination. Each step requires 1 fuel and edges are bidirectional. If no such path is possible, return -1.

Example

edges = [[1,2],[2,3],[3,4],[3,5],[5,6]]
start = 1
end = 6
stations = [4] 
tank_size = 3

Mininum path would be 1 -> 2 -> 3 -> 4 (refuel) -> 3 -> 5 -> 6. Steps = 6

Note that a path of 1 -> 2 -> 3 -> 5 -> 6 is impossible since you will run out of fuel at 5.
Comments (4)