Implement Stack using two Queues
September 17, 2013
Compute x^n (x to the power n)
September 25, 2013

Maximum distance with 50 bikes each having fuel capacity of 100 kms

There are 50 bikes, each with a tank that has the capacity to go 100 kms (when the fuel is full). Fuel tanks of all the bikes are full.
Using these 50 bikes, what is the maximum distance that you can go?
Hint: It’s not that we want all the 50 bikes to be at the end. You can use other bike’s fuel?
Naive Solution:

The most naive solution would be to just make all the bikes go together. Hence, the maximum distance travelled will be 100km.

Better Solution:

Move all the bikes 50km, so that each bike has half tank empty.

Now pour the fuel of 25 bikes (whose tanks are half filled) into other 25 bikes. Now we have 25 bikes will full tanks and these 25 bikes can go upto 100km each

Repeat the same after next 50 km.

Hence the number of bikes will go down after every 50 km, like:

50 -> 25 -> 12 -> 6 -> 3 -> 1

Total distance covered will be 5*50 + 100= 350 kms (At the end you have a bike filled with 100km fuel).

Note: You can further optimize few more km, because we are ignoring one bike’s (50 km fuel) when 25->12 and 3->1.. Since it is not the best solution, I have ignored that.

Best Solution:

In this solution we will vacate the tank of a bike as soon as there is capacity in other bikes (not waiting for 50 km). After 2 km each bike will have 98km of fuel left in them.

So empty one bike into rest 49 bikes. (49*2 = 98).

Again travel a distance of 100/49km, that is sufficient to vacate the fuel of one more bike in other 48 bikes.

The actual number of km traveled will be:

bike_fuel_puzzle

= 449.92 km

This puzzle was asked in the Adobe.

3 Comments

  1. Mayank Sharma says:

    Please explain more.I am not getting it.

  2. Jaskirat Singh says:

    The solution sounds, good but it seems a bit incomplete. Is there a means with which you can justify that there exists no other combination of bikes where you can travel more than this distance?

Leave a Reply to Anonymous Cancel reply

Your email address will not be published. Required fields are marked *