## 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 = 5n**_{1}+1

After dividing the coconuts, the first man hid his share and gave one coconut to the monkey. Therefore, the remaining coconuts are 4n_{1}.

After that, the second man divided the remaining coconuts into five equal shares leaving one coconut. This can be represented as:

4n_{1}= 5n_{2}+1

The remaining coconuts are 4n_{2}.

Now the third man does the same. The remaining equations are:

4n_{2}= 5n_{3}+1, divided by the third man

4n_{3}= 5n_{4}+1, divided by the fourth man

4n_{4}= 5n_{5}+1, divided by the fifth man

4n_{5}= 5n_{6}+1, This is the final division. Each man gets a share of n_{6 }coconuts leaving 1 coconut for the monkey.

Now, working backward from the last equation, 4n_{5}= 5n_{6}+1, adding 4 to this equation:

4n_{5}+4= 5n_{6}+5

4(n_{5}+1)= 5(n_{6}+1), this is an important relation between n_{5 }and n_{6}. We get that (n_{5} + 1) must have a factor of 5.

Now, for the next equation:

4(n_{4}+1)= 5(n_{5}+1)

We know that (n_{5} + 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(n_{4}+1)= 5*5k. From this, we get to know that (n_{4}+1) has a factor of 25.

Working all the way along with the first equation, we get:

(n_{3} + 1) has a factor of 5*5*5.

(n_{2} + 1) has a factor of 5*5*5*5.

(n_{1} + 1) has a factor of 5*5*5*5*5.

Now, add 4 to the first equation:

N+4 = 5n_{1}+5

N+4 = 5(n_{1}+1)

n_{1} has a factor of 5*5*5*5*5 or 3125. The equation can be written as N+4 = 5*3125

**Note: **(n_{1}+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.