1
# Runtime: 32 ms (Top 93.2%) | Memory: 16.18 MB (Top 93.2%)
2

3

4
class Solution(object):
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 + 1
10
# Initialize the required minimum number of pigs...
11
req_pigs = 0
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...
15
req_pigs += 1
16
# Return the required minimum number of pigs...
17
return req_pigs

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0