EDIT: This issue has now been fixed.

I personally feel that @ifyouseewendy's equivalent approach: [https://discuss.leetcode.com/topic/67482/solution-with-detailed-explanation] is significantly better explained than mine and would recommend that you read/upvote this to understand the problem.

--

The basic case (and presumably a significant amount more) are incorrect as more efficient solutions can be generated if we do not use base 2.

Assume for now we have: [**buckets**, 15, 60]

Per pig, we have 5 states that we can detect: death on 15, 30, 45, 60, or life.

Assume for the moment we have 5 buckets and one pig with the above timings.

Represent each bucket as an integer in base 5 (0-indexed).

Pig drinks from bucket 0 at 0 minutes, bucket 1 at time 15 etc...

If the pig is still alive, by elimination, we know that bucket 4 would be poisonous.

This should be trivial to see.

We now increase the number of buckets to 25, we have ceil(log_5(25)) = 2 pigs

Bucket 25 is labelled 44, bucket 1 is labelled 00.

At time **t**, have the first pig drink from the buckets where the first digit is **t**, have the second pig drink when the second digit is **t**. As each pig represents a single digit in base 5, and 25 consists of two base 5 digits, two pigs are necessary. We can determine the value of each digit based on the time of death of each pig. An overlap of the death of two pigs gives us the information of two digits, so nothing is lost.

Example: 18 is poisonous (33 in base 5).

On t=3, one pig is drinking [15,16,17,18,19] and the other is drinking [3,8,13,18,23]. We can see that if both die, the intersection of the sets yields 18.

Given the default input: 1000, 15, 60

The above yields the minimum number of pigs = ceil(log_5(1000)) = 5 pigs.

The OJ currently returns 8 pigs, which is significantly higher.