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 allows 25÷5 = 5 transfer opportunities, but additional tank only has 6 liters. So we can make min(6, 5) = 5 transfers. Total fuel: 25 + 5 = 30 liters. Distance: 30 × 10 = 300 km. Wait, let me recalculate: we can make at most 5 transfers, total fuel = 25 + 5 = 30, distance = 300 km. Actually, the answer should be 310 km which means 31 liters total.
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
Understanding the Visualization
1
Input
Two fuel tanks with given capacities
2
Process
Consume fuel at 10km/L, transfer 1L every 5L used
3
Output
Maximum distance possible
Key Takeaway
🎯 Key Insight: Calculate transfers mathematically instead of simulating step by step
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code