Challenge: Car Fueling

Solve the Car Fueling Problem.

We'll cover the following

Problem


Car Fueling Problem

Compute the minimum number of gas tank refills to get from one city to another.

Input: Integers dd and mm, as well as a sequence of integers: stop1<stop2<<stopnstop_{1} < stop_{2} < \ldots < stop_{n} .
Output: The minimum number of refills to get from one city to another if a car can travel at most mm miles on a full tank. The distance between the cities is dd miles, and there are gas stations at distances stop1,stop2,,stopnstop_{1}, stop_{2},\ldots, stop_{n} along the way. We assume that a car starts with a full tank.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.