Facebook | Onsite | Fuel Economy
Anonymous User
2691

A car, with a tank of volume K liters, and a constant fuel consumption of 1 liter per kilometer, starts driving in a straight line from the origin towards a destination D kilometer away.
Along the road, there are N fuel stations, each at a distance di away from the origin. The cost of fuel at each fuel station is pi per liter.
Write a function to compute the cheapest cost of fuel to reach the destination. Assume that the car starts with a full tank.

Tried to do recurisve solution after station sorting by the price.

One of the hardest Question I encountered in my career.

Comments (9)