Solution: Car Fueling

Solutions for the Car Fueling Problem.

Solution 1: Recursive algorithm

We are going to be greedy; when approaching a gas station, we only stop there if we cannot reach the next one without running out of gas. Pictorially, this looks as follows:

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