Challenge – Camel and Bananas

Question: The owner of a banana plantation has a camel. He wants to transport his 3000 bananas to the market, which is located after the desert. The distance between his banana plantation and the market is about 1000 kilometer. So he decided to take his camel to carry the bananas. The camel can carry at the maximum of 1000 bananas at a time, and it eats one banana for every kilometer it travels.

What is the largest number of bananas that can be delivered to the market?

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

Thanks for all the responses. Quite a few of you have the right answer.

At KM#0, we have 3000 bananas. The maximum bananas the camel can carry is 1000 so the camel must at least make 3 trips from the start point. (Leave #0, Return to #0, Leave #0, Return to #0, Leave #0).
If we move just 1km, we need 1 banana for each step mentioned above thus making a total of 5 bananas for each km.

We continue making 3 trips until we reach a banana count of 2000.
3000 – 5*d = 2000 => d = 200
At #200km, we will have 2000 bananas

At this point, we only need to make 2 trips (Leave #200, Return to #200, Leave #200). This will cost 1 banana for each step thus making a total of 3 bananas for each km.

We continue making 2 trips until we reach a banana count of 1000.
2000 – 3*d = 1000 => d = 333km
At#(200+333) = #534km, we will have 998 bananas

At this point, we need to make one trip so the camel just carries everything and marches toward the market.
Remaining km = 1000 – 534 = 466km. Bananas needed = 466.

Therefore, the bananas remaining once the camel reaches the market is 998 – 466 = 532 bananas. :)

Check out the challenges from previous weeks here.

20 Comments

20 Responses

  1. jah says:

    où est la réponse?

  2. Maks Verver says:

    I arrived at the same conclusion as Adam, but without dividing into many discrete trips.

    The goal is to get a stack of a thousand bananas as close to the market as possible, and then make a final dash for it. When you have a heap of over 1000 bananas, you will need more than one trip to move them all; over 2000, you need move than two (and over 3000, more than three, et cetera, but that doesn’t apply here).

    The first 1000 bananas are used to move the heap to the 200km point (since you need three trips, you need to go there three times, and return two to the farm two times: 3*200+2*200=1000). Then, the next 1000 bananas move the heap another 333⅓km further (two trips forward, one trip back: 2*333⅓+333⅓=1000).

    Now you are 466⅔km away from the market with a thousand bananas left, so you make a dash for it, and you arrive with 533⅓ bananas after nine trips and 2466⅔km traveled.

  3. Jon S says:

    1000 – feed the camel 2000 bananas, carry the remaining 1000 to market , sell them and come back

  4. Andrea says:

    Well, it’s a camel and not a jeep.
    I would feed it after the return and sell 1000 banana at the market.

  5. Adam says:

    The very best you can do is 533 bananas. Chop the trip up into 1000 1km segments bringing the maximum number of bananas each time. At the end of the first 1km leg you have 2995 bananas, two for each trip from home to the 1km marker and back except for the third trip where you do not return home.

    Repeat for each 1km segment on the trip consuming 5 per segment. At 200km 2000 remain. Continue at a cost of 3 per segment.

    At 533km just continue with your remaining 1000 bananas for the remaining 467km. Arrive with 533 bananas.

    This is horribly inefficient as breaking it into 4km trips will only reduce the yield to 532. Using 10km trips 530. At 250km you reach 500, which appears to be optimal.

  6. Doggie says:

    None. He is lazy.

  7. rkachowski says:

    how many bananas can the owner carry?

  8. From a marketing perspective this question sounds like the proverbial dumb ass startup thinking of “I’ll give away my product in the hopes of collecting eyeballs that I will later try to up sell in the hopes of maybe getting some angel, VC or mention on some website that might make me $1500″

    how about I just sell my camel, buy a truck and gas and arrive at the banana market with all my banana’s and then laugh at all the dumb asses who are feeding their camels whilst i am going to the bank with a PROFIT

    how many times are you kids going to waste time trying to make money giving away something?

  9. jah says:

    I divided the journey into 100km stages and move all remaining bananas to each waypoint before moving to the next waypoint.
    It takes 5 trips to move the bananas to the first waypoint. 2500 bananas remain.
    Another 5 trips to move to the second waypoint, 2000 remain.
    It takes only three trips to move the remaining 2000 bananas to the 300km waypoint. 1700 remain.
    3 more trips to the 400km waypoint, 1400 remain.
    3 more trips to the 500km waypoint, 1100 remain. I’m not going to leave 100 bananas here because it’s not worth coming back to get them. So I either feast on 100 bananas or I carry them myself.
    The camel will carry the remaining 1000 bananas 500 km to arrive with 500.
    So my answer is between 500 and 600 depending on how many I ate/carried.

  10. Antonio Yi says:

    The camel will never arrive the market, or it could not get back.
    Poor camel.
    @antonio081014

  11. Doggie says:

    The camel needs the banana to move whether forward or backwards. So you need 2 bananas to go forward 1km and then back to start.

  12. David says:

    Does the camel have to eat a banana to move? E.g., can I carry 1000 bananas 500km, drop off the remaining 500, then return with no bananas?

  13. The camel won’t get there alone, so you must also feed yourself to survive the trip. You can eval the time it will take by using the standard speed a human will walk in the sand and do the math to figure out how much banana the human will have to eat.

  14. DJMcDeez says:

    I dislike these questions because they really discourage lateral thinking. Can the man not carry any bananas himself? Couldn’t he just rig up a simple cart for the camel to pull thereby reducing the amount of weight on the camels back, and hence increasing the number banana’s the camel can carry. Those I would answer well before I actually decided to calculate out the sheer number of bananas that I could take to market by making 3 micro trips, leaving my bananas at the 333 mile marker (keeping enough bananas with me to feed the camel on the way back), pick up another 1000, pick up 333 of the last dropped batch, now drop them off at the 666 mile marker (or there about), keeping 333 with me and using the remaining dropped last batch to feed the rest of the way home for the final 1000. Leaving me with 666 by the time I hit market.

    Terribly inefficient, I would spend more time working out better transportation means rather than the math of what I have left.

  15. codist says:

    This is not a programming question and it incredibly pointless in an interview.

  16. ben says:

    Assuming you keep backtracking to move all your bananas 1 km at a time…

    Initial condition:
    3000 bananas at KM #0.
    Move 1000 bananas to KM #1.
    Consume 1 banana for moving.
    Drop 998 and go back to KM #0, consuming 1 banana.

    There are now 2000 @ #0 and 998 @ #1.

    Move 1000 bananas to KM #1.
    Consume 1 banana for moving.
    Drop 998 and go back to KM #0, consuming 1 banana.

    There are now 1000 @ #0 and 1996 @ #1.

    Move the remaining 1000 bananas from #0 to #1.
    Consume 1 banana for moving.
    You now have 2995 bananas @ #1.

    In other words, for as long as you have >2000 bananas, you consume 5 bananas per km.

    You can therefore cover 200 km for 1000 bananas.

    You are now at KM # 200 with 2000 bananas.

    This time around, you can move 998 bananas forward, go back, and bring the rest forward as well, consuming 3 bananas per km until you have 1000 bananas left.

    You can move 333 additional kilometers this way, consuming 999 and ending up with 1001 bananas @ #533.

    Ditch the extra banana and go straight to the finish with your 1000 bananas, consuming 1 banana per km.

    You can deliver 533!

  17. Doggie says:

    After you make the 3 trips, you won’t have 1998 bananas. Each trip costs you 334*2 bananas since the camel has to go back to the start point. After three trips you will only have 996 bananas. With this, you won’t be able to make two trips.

  18. Tom says:

    Take 3 trips to 334 km at a cost of 334 bananas each.
    The camel will eat 1002 bananas during these trips.
    There are now 1998 bananas remaining.
    Take 2 trips to 833 km at a cost of 499 bananas each.
    The camel will eat 998 bananas during these trips.
    There are now 1000 bananas remaining.
    Take all the remining bananas to the market at a cost of 167 bananas.
    When the camel arrives at the market, there will be 833 bananas remaining.

  19. Tim Kington says:

    I think the best you can do is 500.

    1. Take 1000 bananas, go 250 miles, drop 500, go back home.
    2. Take 1000 bananas, go 250 miles, pick up 250 bananas. Go another 250 miles, drop 500, eat the other 250 on the way back to the first drop point, pick up those 250, eat them on the way home.
    3. Take the last 1000, go 500 miles, pick up the 500 bananas there, eat 500 on the rest of the trip, and you have 500 left.

Leave a Reply

Using Gravatars in the comments - get your own and be recognized!

XHTML: These are some of the tags you can use: <a href=""> <b> <blockquote> <code> <em> <i> <strike> <strong>