Simple Java solution


  • 0
    public class Solution {
        public int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
            if(buckets <=1) return 0;
            if(minutesToDie > minutesToTest) return Integer.MAX_VALUE;
            
            int number_of_tested_bucket = minutesToTest / minutesToDie + 1; //number of buckets tested for each pig
            int number_of_pig = 1; //number of pigs needed
            
            while(Math.pow(number_of_tested_bucket,number_of_pig) < buckets) number_of_pig++;
            return number_of_pig;
        }
    }
    

Log in to reply
 

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