Hi Guys,

I think I have a better solution but the problem is that it is giving number of pigs which in most cases is less than the "Expected answer". I wanted to check with you guys if the solution is correct or not.

Let's consider the numbers which are mentioned in the problem statement, i.e. there are 1000 buckets, it takes a pig 15 minutes (max) to die after it has consumed the poison and we would want the answer in 1 hour (60 minutes).

At the 45th minute let us assume that there are 'n' buckets left to be tested. Let's assume that those 'n' buckets could be tested using 'k' pigs. Then we have 2^k = n.

Assume that a pig died between the 30th and 45th minute, then at the 30th minute we had k + 1 pigs and we could test 2^(k + 1) batches and the size of each batch would have been 'n'. Hence, the total number of buckets at the 30th minute is 2^(k + 1) * 2 ^ k = 2^(2k + 1).

Similarly, at the 15th minute we had 2^(2k + 1) * 2^(k + 2) = 2^(3k + 3) buckets.

And at the 0th minute we had 2^(4k + 6) buckets.

At the 0th minute we also know that there were 1000 buckets, so we arrive at the following equation 2^(4k + 6) = 1000.

Solving for the equation, we get k = ceil((log(1000) / log(2) - 6) / 4) = 1.

At the 45th minute we had 1 pig, so at the 0th minute we had 1 + 3 = 4 pigs.

Now, let you check whether we could solve the problem with 4 pigs.

At the 0th minute we had 4 pigs, so we can divide 1000 into 16 parts (2^4) and figure out which part contains the bucket with the poison. Hence, the size of each part would be ceil(1000 / 16) = 63.

At the 15th minute we had 3 pigs (since one died after drinking the poison) and 63 buckets to test. So, we divide 63 into 8 parts (2^3). Hence, the size of each part would be ceil(63 / 8) = 8.

At the 30th minute we had 2 pigs and 8 buckets to test. Hence, the size of each part would be ceil(8 / 4) = 2.

At the 45th minute we had 1 pig and 2 buckets.

So, we see that only 4 pigs are required to find out which bucket contains the poison.

Please, let me know if the solution is incorrect and where it is incorrect.