The Camel and Bananas — Puzzle for Interview rounds

Question :

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).

Solution :

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 833.

Let us divide the journey into 3 parts. First, the camel takes 1000 bananas and travels 333 KMs and puts the remaining bananas (1000–333 = 667) at first intermediate place and returns back to the source. Similarly, two more times, the camel takes 1000 bananas and travel for 333 KMs and put there remaining. Now, the total numbers of bananas are 2001 at the first intermediate place.

Again, the camel takes 1000 bananas and travels 500 KMs and puts the remaining bananas(1000–500=500) at second intermediate place and returns back to first intermediate place. Similarly one more times, the camel takes 1000 bananas and travels for 500 KMs and put there remaining bananas. Now, the total number of bananas is 1000 at the second intermediate place.

At last, the camel takes 1000 bananas and travels the remaining journey to 167 KMs. Thus, the total number of bananas is 833 at the final destination.

So, the maximum number of bananas can be transferred is 833, if the camel doesn’t eat a banana while returning.

Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.

--

--

--

Upskilling students for tech placements!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Why I won’t be asking children what they want to be when they grow up

Hubspot SWE Co-op Interview Experience and How to Ace it

Spot the difference: Inclusion, Diversity and Equity

PWiC Islamabad Meetup — Event Highlights and

Practicing and Performing

Great careers don’t just happen.

How Google nearly Destroyed our Business

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Placewit

Placewit

Upskilling students for tech placements!

More from Medium

Class Quiz

Leetcode 862. Shortest Subarray with Sum at Least K

“Delete and Earn” problem using Dynamic Programming

LeetCode 253 — Meeting Rooms 2