Fewest fuel stops
A car starts with fuel units and must travel target units, using one unit per
distance. stations is a list of (position, amount) sorted by position. Write
min_refuels(target, fuel, stations) that returns the fewest stops needed to reach the
target, or -1 if it cannot.
min_refuels(100, 10, [(10, 60), (20, 30), (30, 30), (60, 40)]) -> 2
min_refuels(1, 1, []) -> 0
min_refuels(100, 1, [(10, 100)]) -> -1
The point is to practise a greedy with a heap: pass stations and remember their fuel, and only when stuck, take the biggest amount you passed.
def min_refuels(target, fuel, stations):
...