Poor Pigs

hard math combinatorics

Problem

Given some buckets where exactly one contains poison, find the minimum number of pigs needed to identify the poisoned bucket within minutesToTest, given each test cycle takes minutesToDie minutes.

Inputbuckets = 1000, minutesToDie = 15, minutesToTest = 60
Output5
t = 60/15 + 1 = 5; 5⁵ = 3125 ≥ 1000.

import math
def poor_pigs(buckets, dieM, testM):
    t = testM // dieM + 1
    return math.ceil(math.log(buckets) / math.log(t))
function poorPigs(buckets, dieM, testM) {
  const t = Math.floor(testM / dieM) + 1;
  return Math.ceil(Math.log(buckets) / Math.log(t));
}
class Solution {
    public int poorPigs(int buckets, int dieM, int testM) {
        int t = testM / dieM + 1;
        return (int) Math.ceil(Math.log(buckets) / Math.log(t));
    }
}
int poorPigs(int buckets, int dieM, int testM) {
    int t = testM / dieM + 1;
    return (int) ceil(log(buckets) / log(t));
}
Time: O(1) Space: O(1)