**Question:** Given a fleet of 50 trucks, each with a full fuel tank and a range of 100 miles, how far can you deliver a payload? You can transfer the payload from truck to truck, and you can transfer fuel from truck to truck. Assume all the payload will fit in one truck.

**Challenge:** Do you know the answer to this question? Post in the comments. Answers will be posted on ** April 22th**.

Thanks Ole Sandbu, Czikus and Vanta for the answers.

We want to use as little fuel as possible so we try minimize the number of trucks we use as we go along. Let’s say we start with all 50 trucks with full fuel (5000 miles range). For each mile, we lose 50 miles in range. After two miles, we lose 100 miles leaving us with 4900 miles. This can be supported by 49 trucks so we drop one truck.

As you can see for every 100 miles we lose in range, we drop a truck.

50 trucks: 100/50

49 trucks: 100/49

…

Total distance = 100/50 + 100/49 + 100/48 + … + 100/2 + 100/1 (harmonic series) = 449.920533833

Meanwhile check out the challenges from previous weeks **here**.

**If you're looking for some serious preparation for your interviews, I'd recommend this book written by a lead Google interviewer. It has 189 programming questions and solutions:**

2400-2500 miles with some practical assumptions…

I don’t know if it is practical to have a 50-truck trailer in real life. And neither is it practical to keep siphoning off gas at random points along the road. Real life and theory are very different! 🙂

1) Sell one truck’s gas (or whatever it takes) to buy 48 fuel containers

2) Truck#1 has payload

3) Truck#2 has 48 fuel containers with fuel emptied from 48 trucks (assuming it fits, otherwise the solution changes a bit)

4) Both trucks go for 100 miles, refuel both trucks and do this 24 times

Without the constraint that the fleet is based at one location, 5000 mi.

5000 miles.

The puzzle doesn’t make any restrictions regarding how the payload might impact the mileage. Therefore, the trucks arrange themselves in a connected train. The first truck pulls the rest of the chain until running out of gas 100 miles later. That truck drops off the chain and the remaining 49 continue on in the same pattern. Alternatively, the last truck in the chain pushes the rest. This way, no gas is wasted moving out of the way of the train.

using an approximation for harmonic progression: 100 * (ln(50 + 0.5) + 0.5772 + 0.03759/(50*50 + 1.171)) = 449.9188

350 miles. When all are in the same starting point, 100 miles…if refueling at half, 350 miles, but I’ve (50-32) fuel trucks that i don’t need.. so extra fuel that I don’t know how to manage. Every 4 trucks are able to go 200 miles with refuelling and grouping 32 is the result, 350miles.

449.920533833

449.9205338330

With one truck: We can only go 100 miles.

with two trucks: We drive 50 miles and then give 50 miles worth of fuel to the truck carrying the load, and can then drive another 100 miles. So in total 150 miles.

For 50 trucks we want to find out how far we can go before we can give all the fuel from one truck to all the others in order to fill their tanks.

After travelling 2 miles the trucks will have enough fuel for 98 miles left. Therefore if one truck gives 2 miles worth of fuel to each other truck, 49 trucks will have full tanks. This is because 98/49 = 2. If we let n be the number of trucks and x be the number of miles we should go, this can be generalised into the following formula: (100-x)/(n-1) = x, which can be simplified into x=100/n.

So the total distance travelled becomes sum[n=50..1](100/n), which is equal to 100 * sum[n=1..50](1/n):

100 * (1/1 + 1/2 + 1/3 + 1/4 .. + 1/50)

As far as I know, there is no easy way to evaluate this by hand, but the following python program will do the job:

`n = 50`

sum = 0

for i in range(1, n+1):

sum += 1.0 / i

sum *= 100

print sum

This prints the answer of 449.920533833.

518.738