Facebook | Onsite | Fuel Economy

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2020-04-29Added By Anonymous
Source: Link

Company: Meta (Facebook)
Role: unknown
Interview Stage: Onsite
Location: unknown
Year: unknown

Original Post Content:

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 recursive solution after station sorting by the price.

One of the hardest Question I encountered in my career.

Comments