Skip to content

458. Poor Pigs 👎

  • Time: $O(1)$
  • Space: $O(1)$
1
2
3
4
5
6
class Solution {
 public:
  int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
    return ceil(log(buckets) / log(minutesToTest / minutesToDie + 1));
  }
};
1
2
3
4
5
class Solution {
  public int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
    return (int) Math.ceil(Math.log(buckets) / Math.log(minutesToTest / minutesToDie + 1));
  }
}
1
2
3
class Solution:
  def poorPigs(self, buckets: int, minutesToDie: int, minutesToTest: int) -> int:
    return ceil(log(buckets) / log(minutesToTest // minutesToDie + 1))