Total Distance Traveled

A truck has two fuel tanks. You are given two integers, mainTank representing the fuel present in the main tank in liters and additionalTank representing the fuel present in the additional tank in liters.

The truck has a mileage of 10 km per liter. Whenever 5 liters of fuel get used up in the main tank, if the additional tank has at least 1 liters of fuel, 1 liters of fuel will be transferred from the additional tank to the main tank.

Return the maximum distance which can be traveled.

Note: Injection from the additional tank is not continuous. It happens suddenly and immediately for every 5 liters consumed.

Example 1
InputmainTank = 5, additionalTank = 10
Output60
After spending 5 litres of fuel, 1 litre is injected from the additional tank, then the remaining 1 litre is used for a total distance of 60 km.
Example 2
InputmainTank = 1, additionalTank = 2
Output10
After spending 1 litre of fuel, the main tank becomes empty, so the total distance traveled is 10 km.

Constraints

  • 1 <= mainTank, additionalTank <= 100

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate