Python code based on lano1's idea


  • 1
    N

    Based on lano1'idea:
    https://discuss.leetcode.com/topic/66856/major-flaw-in-current-algorithm-fixed
    Here is python code:

        def poorPigs(self, buckets, minutesToDie, minutesToTest):
            """
            :type buckets: int
            :type minutesToDie: int
            :type minutesToTest: int
            :rtype: int
            """
            # corner case
            if buckets == 1:
                return 0
            if minutesToTest // minutesToDie <= 1:
                return buckets - 1
            # general case: just get the n in n^(test_times + 1) = buckets
            return int(math.ceil(math.log(buckets, (minutesToTest // minutesToDie) + 1)))
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.