Solution
Let the original number of coconuts be N. The first man divided the coconuts into five equal shares leaving one coconut. This can be represented as:
N = 5n1+1
After dividing the coconuts, the first man hid his share and gave one coconut to the monkey. Therefore, the remaining coconuts are 4n1.
After that, the second man divided the remaining coconuts into five equal shares leaving one coconut. This can be represented as:
4n1= 5n2+1
The remaining coconuts are 4n2.
Now the third man does the same. The remaining equations are:
4n2= 5n3+1, divided by the third man
4n3= 5n4+1, divided by the fourth man
4n4= 5n5+1, divided by the fifth man
4n5= 5n6+1, This is the final division. Each man gets a share of n6 coconuts leaving 1 coconut for the monkey.
Now, working backward from the last equation, 4n5= 5n6+1, adding 4 to this equation:
4n5+4= 5n6+5
4(n5+1)= 5(n6+1), this is an important relation between n5 and n6. We get that (n5 + 1) must have a factor of 5.
Now, for the next equation:
4(n4+1)= 5(n5+1)
We know that (n5 + 1) has a factor of 5. Thus, it can be written as 5k, where k is a constant. The equation can be written as 4(n4+1)= 5*5k. From this, we get to know that (n4+1) has a factor of 25.
Working all the way along with the first equation, we get:
(n3 + 1) has a factor of 5*5*5.
(n2 + 1) has a factor of 5*5*5*5.
(n1 + 1) has a factor of 5*5*5*5*5.
Now, add 4 to the first equation:
N+4 = 5n1+5
N+4 = 5(n1+1)
n1 has a factor of 5*5*5*5*5 or 3125. The equation can be written as N+4 = 5*3125
Note: (n1+1) may have factors other than 3125, but for minimizing, we are taking the least possible factors.
N+4 =15625
N=15621
Therefore, the smallest possible value of the initial number of coconuts is 15621.
Answer: 15621
Check out this problem - 8 Queens Problem
Frequently Asked Questions
How should we solve the puzzles during the interview?
Think about the problem and try to understand the question. Ask for clarifications if you feel that you do not understand the puzzle. Getting the right answer is not as important as your approach. Always explain your approach while answering.
Best tips for preparing for puzzles for interviews?
The best approach is practicing different puzzles and solving the previously asked puzzles.
Should we always reach the correct answer to the puzzle during the interview?
You should focus on your approach and your ability to convey it to the interviewer. Sometimes, you may not be able to reach the correct answer, but if your approach is right, it does not matter much.
Conclusion
In this blog, we solved a very famous puzzle known as the Monkey and the coconut problem. We looked at its solution extensively and saw the mathematical approach to solve this problem.
Recommended Readings:
Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, etc. on Coding Ninjas Studio.
Also check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.