You have a truck moving around a circular track with gas stations spaced out around the circle. Each station has a finite amount of gas. The gas tank on the truck is infinit
The solution to this problem is based on a greedy algorithm. It is based on the following two observations.
if the total gas > cost, there must be a start index to finish the circle, else there isn't;
as to an index i, if from i, j is the first index that we cannot reach, then any index from i to j, cannot be the start index.
For more explanation, have a look at the following link - Gas Station problem.