#2739
Total Distance Traveled
pupil · 505 · lc easy +27 · verified · 41.2% accepted · 326 likes · top 21%
Description
A truck has a mainTank and an additionalTank (both in liters). The truck travels 10 km per liter. Each time 5 liters are consumed from the main tank, 1 liter transfers from the additional tank if available. Return the maximum km the truck can travel.
Example 1:
Input: mainTank = 5, additionalTank = 10
Output: 60
Explanation:
After spending 5 litre of fuel, fuel remaining is (5 - 5 + 1) = 1 litre and distance traveled is 50km.
After spending another 1 litre of fuel, no fuel gets injected in the main tank and the main tank becomes empty.
Total distance traveled is 60km.
Example 2:
Input: mainTank = 1, additionalTank = 2
Output: 10
Explanation:
After spending 1 litre of fuel, the main tank becomes empty.
Total distance traveled is 10km.
Code
1
2
3