1
# Runtime: 32 ms (Top 93.2%) | Memory: 16.18 MB (Top 93.2%)5
def poorPigs(self, buckets, minutesToDie, minutesToTest):6
# Calculate the max time for a pig to test buckets...7
# Note that, max time will not be (minutesToTest / minutesToDie)...8
# Thinking about all pigs drinking all buckets at last, but no one died immediately, so the poison bucket is the last bucket...9
max_time = minutesToTest / minutesToDie + 110
# Initialize the required minimum number of pigs...12
# To find the minimum number of pigs, find the minimum req_pigs such that Math.pow(max_time, req_pigs) >= buckets...13
while (max_time) ** req_pigs < buckets:14
# Increment until it will be greater or equals to bucket...16
# Return the required minimum number of pigs...