All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0401_0500.s0458_poor_pigs.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.28
Show newest version
package g0401_0500.s0458_poor_pigs

// #Hard #Dynamic_Programming #Math #Combinatorics
// #2022_12_27_Time_133_ms_(80.00%)_Space_32.8_MB_(80.00%)

@Suppress("NAME_SHADOWING")
class Solution {
    fun poorPigs(buckets: Int, minutesToDie: Int, minutesToTest: Int): Int {
        var buckets = buckets
        if (buckets-- == 1) {
            return 0
        }
        val base = minutesToTest / minutesToDie + 1
        var count = 0
        while (buckets > 0) {
            buckets /= base
            count++
        }
        return count
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy