A person has 3000 bananas and a camel. The person wants to transport the maximum number of bananas to a destination which is 1000 KMs away, using only the camel as a mode of transportation. The camel cannot carry more than 1000 bananas at a time and eats a banana every km it travels. What is the maximum number of bananas that can be transferred to the destination using only camel (no other mode of transportation is allowed).
Let’s see what we can infer from the question:
- We have a total of 3000 bananas.
- The destination is 1000KMs
- Only 1 mode of transport.
- Camel can carry a maximum of 1000 banana at a time.
- Camel eats a banana every km it travels.
With all these points, we can say that person won’t we able to transfer any banana to the destination as the camel is going to eat all the banana on its way to the destination.
But the trick here is to have intermediate drop points, then, the camel can make several short trips in between.
Also, we try to maintain the number of bananas at each point to be multiple of 1000.
Let’s have 2 drop points in between the source and destination.
With 3000 bananas at the source. 2000 at a first intermediate point and 1000 at 2nd intermediate point.
3000 x km 2000 y km 1000 z km
——————–> | —————> | ———————–>
<——————- | <————– |
——————-> | —————> |
<—————— | |
——————-> | |
- To go from source to IP1 point camel has to take a total of 5 trips 3 forward and 2 backward. Since we have 3000 bananas to transport.
- The same way from IP1 to IP2 camel has to take a total of 3 trips, 2 forward and 1 backward. Since we have 2000 bananas to transport.
- At last from IP2 to a destination only 1 forward move.
Let’s see the total number of bananas consumed at every point.
- From the source to IP1 its 5x bananas, as the distance between the source and IP1 is x km and the camel had 5 trips.
- From IP1 to IP2 its 3y bananas, as the distance between IP1 and IP2 is y km and the camel had 3 trips.
- From IP2 to destination its z bananas.
We now try to calculate the distance between the points:
- 3000 – 5x = 2000 so we get x = 200
- 2000-3y = 1000 so we get y = 333.33 but here the distance is also the number of bananas and it cannot be fraction so we take y =333 and at IP2 we have the number of bananas equal 1001, so its 2000-3y = 1001
- So the remaining distance to the market is 1000 -x-y =z i.e 1000-200-333 => z =467.
So from IP2 to the destination point camel eats 467 bananas. The remaining bananas are 533.
So the maximum number of bananas that can be transferred is 533.
If the camel doesn’t eat a banana while returning, which means when it doesn’t have a banana, then the maximum number of bananas that can be transferred will be 666.
Let us divide the journey into 2 parts, First, the camel takes 1000 bananas and travels for 666 Kms and puts the remaining bananas (1000-666=334) and returns back to the source, Again he takes 1000 bananas and travels for 666 Kms, puts there remaining and again goes back. Now, at this second place, the total numbers of bananas are 1002 and the remaining distance to travel is 334 Kms, Now the camel takes 1000 bananas and travels 334 Kms to the final destination. At the end of the journey, it will have (1000-334) 666 bananas.
The distance of the first stop can be taken at 667 Kms also, the result will be the same.
Refer the following link for a detailed explanation: https://puzzling.stackexchange.com/a/232
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.