Total Distance Traveled - Problem
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 liter of fuel, 1 liter 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.
Input & Output
Example 1 — Basic Transfer
$
Input:
mainTank = 5, additionalTank = 10
›
Output:
60
💡 Note:
Main tank has 5 liters. After using 5 liters (50 km), we can transfer 1 liter from additional tank. Total fuel used: 5 + 1 = 6 liters. Distance: 6 × 10 = 60 km.
Example 2 — Multiple Transfers
$
Input:
mainTank = 25, additionalTank = 6
›
Output:
310
💡 Note:
Main tank has 25 liters. The truck uses fuel and transfers occur every 5 liters used: 5 transfers happen at 5L, 10L, 15L, 20L, 25L used, and one more at 30L used (from transferred fuel), totaling 6 transfers. Total fuel used: 25 + 6 = 31 liters. Distance: 31 × 10 = 310 km.
Example 3 — No Additional Fuel
$
Input:
mainTank = 4, additionalTank = 0
›
Output:
40
💡 Note:
No additional fuel available, so we can only use the 4 liters in main tank. Distance: 4 × 10 = 40 km.
Constraints
- 1 ≤ mainTank, additionalTank ≤ 100
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code